cancel
Showing results for 
Search instead for 
Did you mean: 

JSPDyn page using a bean

Former Member
0 Kudos

Trying to create a pretty simple JSPDyn page with a single bean. I am using NWDS to generate the code. I am trying to set some initial data in bean to be used on the page later, but it always comes back as NULL. It's like the creation the generation of the page creates a new instance of bean and loses the reference I create in the controller.

Here is the code for the dynpage controller:



package com.my.test;

import com.my.test.bean;
import com.sapportals.htmlb.*;
import com.sapportals.htmlb.enum.*;
import com.sapportals.htmlb.event.*;
import com.sapportals.htmlb.page.*;
import com.sapportals.portal.htmlb.page.*;
import com.sapportals.portal.prt.component.*;

public class myTest extends PageProcessorComponent {

  public DynPage getPage(){
    return new myTestDynPage();
  }

  public static class myTestDynPage extends JSPDynPage{
  
    private bean myBean = null;
  
    public void doInitialization(){
      IPortalComponentProfile profile = ((IPortalComponentRequest)getRequest()).getComponentContext().getProfile();
      Object o = profile.getValue("myBean");
      if(o==null || !(o instanceof bean)){
        myBean = new bean();
        profile.putValue("myBean",myBean);
      } else {
          myBean = (bean) o;
      }
      // fill your bean with data here...
      myBean.setOutput("test message");
    }

    public void doProcessAfterInput() throws PageException {
    }

    public void doProcessBeforeOutput() throws PageException {
      this.setJspName("myTest.jsp");
    }
  }
}

Notice I am setting the data up after the comment "//fill your bean data here". SAP code generator inserted this comment.

and here is the bean code



package com.my.test;


import java.io.Serializable;

public class bean implements Serializable {
	private String output;
	public String getOutput( ){
		return output;
	}
	public void setOutput( String value ){
		output = value;
	}
}

and finally the jsp page




<jsp:useBean id="myBean" scope="application" class="com.my.test.bean" />
<hbj:content id="myContext" >
  <hbj:page title="PageTitle">
   <hbj:form id="myFormId" >
     The value of Output is <%= myBean.getOutput( ) %>
   </hbj:form>
  </hbj:page>
</hbj:content>

the output is:

The value of Output is null

Anyone have any idea what I am doing wrong here.

Thanks in advance.

Clark

Accepted Solutions (1)

Accepted Solutions (1)

former_member182598
Active Contributor
0 Kudos

Hi Clark,

Open the portalapp.xml and delete these two lines

<property name="ComponentType" value="jspnative"/>

<property name="JSP" value="pagelet/myTest.jsp"/>

Rebuild and deploy and it should work.

Thanks

Prashant

Former Member
0 Kudos

Thanks so much. That did it.

Clark

Answers (0)