on 07-30-2008 3:50 AM
Hi,
I am using JSPDynpages and am trying to save a value in my bean and get access to this value on my JSP page. I have not been able to get the value from my bean to the jsp page any thoughts on what I may be doing wrong would be appreciated.
Below is the code I am working with
Mike
public void doProcessBeforeOutput() throws PageException
{
myBean myBean = new myBean();
((IPortalComponentRequest)getRequest()).getServletRequest().setAttribute("myBean", myBean);
// fill your bean with data here...
myBean.setBappiReturn( "Hello World");
this.setJspName("JSPTest.jsp");
}
-
<%@ taglib uri="tagLib" prefix="hbj" %>
<%@ page import="com.sapportals.portal.prt.runtime.PortalRuntime" %>
<%@ page import="com.sapportals.portal.prt.resource.IResource" %>
<jsp:useBean id="myBean" scope="request" class="myBean.myBean" />
<hbj:content id="myContext" >
<hbj:page title="PageTitle">
<hbj:form id="myFormId" >
<%= myBean.getBappiReturn()%>
</hbj:form>
</hbj:page>
</hbj:content>
-
import java.io.Serializable;
public class myBean implements Serializable
{
public String bappiReturn = "";
/**
@return
*/
public String getBappiReturn() {
return bappiReturn;
}
/**
@param string
*/
public void setBappiReturn(String string) {
bappiReturn = string;
}
}
-
<?xml version="1.0" encoding="UTF-8"?>
<application>
<application-config>
<property name="PrivateSharingReference" value="com.sap.portal.htmlb,com.sap.portal.themes.lafservice,com.sap.portal.navigation.service,com.sap.portal.navigation.helperservice,com.sap.portal.pagebuilder,jco,jcoclient"/>
</application-config>
<components>
<component name="JSPProject">
<component-config>
<property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld" />
<property name="ClassName" value="JSPProject.JSPProject"/>
<property name="ComponentType" value="jspnative"/>
<property name="JSP" value="pagelet/JSPTest.jsp"/>
</component-config>
<component-profile>
<property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld"/>
</component-profile>
</component>
</components>
<services/>
</application>
HI Mike,
in the public void doInitialization()----
/***********Setting of the Bean object***************/
IPortalComponentSession componentSession =
((IPortalComponentRequest) getRequest()).getComponentSession();
Object o = componentSession.getValue("myBean");
if (o == null || !(o instanceof ICDProjectStatementBean)) {
myBean = new ICDProjectStatementBean();
componentSession.putValue("myBean", myBean);
} else {
myBean = (ICDProjectStatementBean) o;
}
/***********End of Setting of the Bean object***************/
and in the JSP :-
<jsp:useBean id="myBean" scope="session" class="org.isdb.ICDPS.ICDProjectStatementBean" />
you have taken scope as request.
Try to do like the given code, hope this may help you.
Regards,
Deepak
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you all for the help.
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mike,
Add
myBean myBean = new myBean(); inside your JSP and then try....
more over,inside your bean class you can delete "implements serilizable" if you want so...
and in your portalapp.xml remove
<property name="ComponentType" value="jspnative"/>
entry.
so that your JSP looks like...
<%@ taglib uri="tagLib" prefix="hbj" %>
<%@ page import="com.sapportals.portal.prt.runtime.PortalRuntime" %>
<%@ page import="com.sapportals.portal.prt.resource.IResource" %>
<hbj:content id="myContext" >
<hbj:page title="PageTitle">
<hbj:form id="myFormId" >
//added here
<% myBean myBean = new myBean(); %>
//added till here
<%= myBean.getBappiReturn()%>
Regards,
Srinivas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mike,
As deepak said, in the jsp that you are using the code to get the value kept in the session keep the scope = "session"
Kind Regards,
Manoj Durairaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kumar,
Thank you for all the help, it is appreciated. Is it possible for you to send me the test application that is working for you. This way I can confirm whether there is an issue with my setup.
My e-address can be found in my profile.
Thank you.
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mike,
This is at the remotest of conditions that one uses it. How about using the session property whose value will die with the age of the browser.
request.getServletRequest().getSession(true).setAttribute("<ABC>",value that you need to access in the jsp);
And in the use the code -- String test = (String)session.getAttribute("<ABC>");
Try this and this should for sure help you.
Kind Regards,
Manoj Durairaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kummar,
Thanks for the quick response. It did not work. I did award points for the quick response.
Mike
P.S> Does anyone have a working test application that you could send me to test.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kumar,
I did try it, but it did not help.
Thank you.
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Change the property <property name="PrivateSharingReference" value="com.sap.portal.htmlb,com.sap.portal.themes.lafservice,com.sap.portal.navigation.service,com.sap.portal.navigation.helperservice,com.sap.portal.pagebuilder,jco,jcoclient"/> in to <property name="SharingReference" value="com.sap.portal.htmlb, usermanagement, knowledgemanagement, landscape, htmlb, exportalJCOclient, exportal"/>
and remove this property in <component-config>
<property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld" />
<property name="ComponentType" value="jspnative"/>
It will work.
Regards,
Kumar
Thanks Deepak and Harini for a quick response. I did try what you both suggested however it did not work.
Any thoughts.
Mike
P.S> I awarded points for your quick response
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI,
Create bean with application scope. Then this will work.
Also remove these lines from portalapp.xml
<property name="ComponentType" value="jspnative"/>
<property name="JSP" value="pagelet/JSPTest.jsp"/>
Regards,
Harini S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.