on 11-11-2005 2:53 PM
Hi everybody,
as already read several times, I've got the same problem performing my first steps in EP content programming.
Within the jsp the bean is not present. When I define a non-default constructor for the bean, an exception is thrown, so the jsp tries to create a new instance, because it finds nothing in the session.
But where is my object?
Instead of session.(set|get)Attribute I also tried componentContext().(put|get)Value and an application scope. Didn't work either.
My DynPage:
public static class Ralbi1stPageDynPage extends JSPDynPage{
MyBean myBean_;
public void doInitialization(){
getMyBean();
}
public void doProcessAfterInput() throws PageException {
MyBean myBean = getMyBean();
InputField input = (InputField)getComponentByName("inputName");
if(input != null) {
myBean.setTextView("Your name: "+input.getValueAsDataType().toString());
}
else
myBean.setTextView("input not found.");
}
public void doProcessBeforeOutput() throws PageException {
this.setJspName("Ralbi1stPage.jsp");
}
public void onClick(Event event) throws PageException {
}
private MyBean getMyBean() {
IPortalComponentRequest request = (IPortalComponentRequest)this.getRequest();
MyBean myBean = (MyBean)request.getServletRequest().getSession().getAttribute("myBean");
if(myBean == null) {
myBean_ = new MyBean();
myBean_.setText("Submit");
request.getServletRequest().getSession().setAttribute("myBean", myBean_);
myBean = myBean_;
}
return myBean;
}
}
My JSP:
<%@ taglib uri= "tagLib" prefix="hbj" %>
<jsp:useBean id="myBean" type="com.werum.ralbi.view.MyBean" scope="session"/>
<hbj:content id="myContext" >
<hbj:page title="PageTitle">
<hbj:form id="myFormId" >
<hbj:tray id="example" design="BORDER" width="500" title="NameCheck" isCollapsed="false">
<hbj:trayBody>
<br/><font size="-1">Bean: <%=myBean%>/<%=myBean.getText()%>/<%=myBean.getTextView()%><br/></font>
<hbj:inputField id="inputName" type="String" design="STANDARD" width="100" maxlength="100" tooltip="please enter your name">
</hbj:inputField>
<hbj:button id="myButton" text="<%=myBean.getText()%>" onClick="click" tooltip="submit">
</hbj:button>
<br/><br/>
<hbj:textView id="zeile1" encode="false" tooltip="your name">
<% zeile1.setText(":"+myBean.getTextView()+":"); %>
</hbj:textView>
</hbj:trayBody>
</hbj:tray>
</hbj:form>
</hbj:page>
</hbj:content>
My portalapp.xml:
<?xml version="1.0" encoding="utf-8"?>
<application alias="RalbiPortalApplication">
<application-config>
<property name="PrivateSharingReference" value="com.sap.portal.htmlb"/>
</application-config>
<components>
<component name="Ralbi1stPage">
<component-config>
<property name="ClassName" value="com.werum.ralbi.Ralbi1stPage"/>
<property name="SecurityZone" value="com.werum.ralbi.Ralbi1stPage/high_safety"/>
<property name="ComponentType" value="jspnative"/>
<property name="JSP" value="pagelet/Ralbi1stPage.jsp"/>
</component-config>
<component-profile>
<property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld"/>
</component-profile>
</component>
</components>
<services/>
</application>
I took the sample from a book, and had to change some details in order to get it run on Version 6.40 SP11.
These hints I got from this forum, but none of them helped to leave in success.
Kind Regards,
Ralf
Hi Ralf,
Guess you using NDS to develop JSPDynpage iView.
When you select session or application, it auto creates the Bean initialization stuff!
Also, U need to delete:
<property name="ComponentType" value="jspnative"/>
<property name="JSP" value="pagelet/Ralbi1stPage.jsp"/>
from portalapp.xml (Itz not needed)
If u need a document on how to create One..
ping me on sapmails@gmail.com
Regards,
P.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ralf,
P was absolutely correct, when you develop a JDPDynPage based application, the lines must be deleted! That's definitive!
> I get an error-message in EP
What kind of?
> I can't find the appropriate logfile
> with the detailed message
\usr\sap\<ID>\JC00\j2ee\cluster\server0\log, there the latest default.X.trc
Hope it helps
Detlev
PS: Please consider rewarding points for helpful answers on SDN. Thanks in advance!
Hi Detlev,
I found the log but I'm slightly tangled.
I get a ClassCastException when I cast the object that I got from the session to my bean-type.
What's that? My traces tell me, that it's the correct type. It works, when I remove the attrib in doInitialisation and create a new one afterwords.
What kind of class is stored in the session-attribute?
Regards,
Ralf
Hi Detlev,
I think, I have to revise my euphoria.
I still had the statement
MyBean myBean = request.getSession().getAtt...
in my JSP. When I delete this and use the <jsp:useBean scope="session"> statement, then the bean is empty. In my traces I can see, that two instances of my bean have been created.
Why that?
Another thing: I tried custom taglibs. No way. Not the simplest tag is functioning. I allways get an...
Caused by: com.sapportals.portal.prt.component.PortalComponentException: Error occurs when the jsp parser try to read the jsp
at com.sapportals.portal.prt.servlets_jsp.server.jsp.JSPCompiler.compile(JSPCompiler.java:96)
at com.sapportals.portal.prt.servlets_jsp.server.jsp.JSPCompiler.run(JSPCompiler.java:140)
at com.sapportals.portal.prt.core.broker.JSPComponentItem.compileJSP(JSPComponentItem.java:279)
at com.sapportals.portal.prt.core.broker.JSPComponentItem.getComponentInstance(JSPComponentItem.java:129)
at com.sapportals.portal.prt.core.broker.PortalComponentItemFacade.service(PortalComponentItemFacade.java:355)
at com.sapportals.portal.prt.core.broker.PortalComponentItem.service(PortalComponentItem.java:934)
at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:435)
... 23 more
Caused by: com.sapportals.portal.prt.servlets_jsp.server.jsp.ParseException: java.lang.NullPointerException
at com.sapportals.portal.prt.servlets_jsp.server.jsp.TagBeginGenerator.init(TagBeginGenerator.java:147)
at com.sapportals.portal.prt.servlets_jsp.server.jsp.syntax.xmlsyntax.CustomJspTag.action(CustomJspTag.java:114)
The documentation is slightly rare about taglib.
Regards,
Ralf
That was quick!
Here the init code:
public void doInitialization(){
System.out.println("---> trc: onInitialization()");
IPortalComponentRequest request = (IPortalComponentRequest)this.getRequest();
MyFirstSAPBean myBean = new MyFirstSAPBean();
myBean.setText("submit");
request.getServletRequest().getSession().setAttribute("myBean", myBean);
System.out.println(" myBean created:"+myBean);
System.out.println("<--- trc: onInitialization()");
}
And here the JSP:
<%@ taglib uri= "tagLib" prefix="hbj" %>
<%@ page import="com.werum.ralbi.view.*" %>
<jsp:useBean id="myBean" class="com.werum.ralbi.view.MyFirstSAPBean" scope="session" />
<%
System.out.println("---> JSP: "+myBean);
%>
<hbj:content id="myContext" >
<hbj:page title="PageTitle">
<hbj:form id="myFormId" >
<hbj:inputField id="inputName" type="String" design="STANDARD" width="100" maxlength="100" tooltip="Please enter your name:"/>
<hbj:button id="myButton" text="<%=myBean.getText()%>" onClick="click" tooltip="submit"/>
</hbj:form>
</hbj:page>
</hbj:content>
Thanks a lot.
Regards,
Ralf
Hi Ralf,
quick again, that's how I work
scope="session" in the JSP means, that the bean has to be put into the PortalComponentSession, i.e. <i>componentRequest.getComponentSession().putValue(String key, Object value);</i>
Alternatively, you should be able to call putValue on the HttpSession.
See http://help.sap.com/saphelp_nw04/helpdata/en/3a/ec20401fe52402e10000000a1550b0/frameset.htm and http://help.sap.com/saphelp_nw04/helpdata/en/2e/c87f41849d030de10000000a1550b0/frameset.htm for further details.
Hope it helps
Detlev
Hi Detlev,
really quick
Now it works. Bean and Tags.
Thanks a lot.
As remarked this are my first steps with EP, have programmed under Tomcat for last 3 years.
Where can I find some documentation concerning these pitfalls, or better to avoid these pitfalls. It is really different as programming under tomcat or Websphere.
The tutorials I've found are partially deprecated.
Kind regards,
Ralf
Hi Ralf,
> have programmed under Tomcat for last 3 years.
That similiar how I got into the EP SAP-Java world. Yeah, you have to learn that the implementation is not always following standards...
> Where can I find some documentation concerning
> these pitfalls
I would suggest two things:
(a) Read the developer guide(s) and check out everything "live" on your portal installation. Just to get experience as fast as possible.
(b) Read SDN threads and try to resolve the issues. You will quite fast learn things you can reuse later in your life, which you just wouldn't be aware of otherwise.
Hope it helps
Detlev
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.