Skip to Content
0
Former Member
Nov 11, 2005 at 02:53 PM

And again bean-data in JSPDynPage

21 Views

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