cancel
Showing results for 
Search instead for 
Did you mean: 

Bean usage in JSPDynPage

0 Kudos

I am trying a very simple example.But i am unable to get what i want... i am getting blank field(null)

Source code goes as follows:

Dynpage:

package com.abc.basicexample;

import com.abc.basicexample.myBean;

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 b extends PageProcessorComponent {

public DynPage getPage(){

return new bDynPage();

}

public static class bDynPage extends JSPDynPage{

public void doInitialization(){

}

public void doProcessAfterInput() throws PageException {

}

public void doProcessBeforeOutput() throws PageException {

((IPortalComponentRequest)getRequest()).getServletRequest().setAttribute("myBean", myBean);

myBean myBean = new myBean();

myBean.setName("bb");

this.setJspName("jsp2.jsp");

}

}

}

JSP:

<jsp:useBean id="myBean" scope="request" class="com.abc.basicexample.myBean" />

<hbj:content id="myContext" >

<hbj:page title="PageTitle">

<hbj:form id="myFormId" >

before:<%

out.println(myBean.getName());

/*myBean.setName("this my first Bean");

out.println("<br>");

out.println("after:");

out.println(myBean.getName());

*/

%>

</hbj:form>

</hbj:page>

</hbj:content>

Bean:

package com.abc.basicexample;

import java.io.Serializable;

public class myBean implements Serializable {

public String name;

public void setName(String name)

{

this.name=name;

}

public String getName()

{

return name;

}

}

Any pointers to where am i going wrong..

Thanks & Regards,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Please try the following steps:

First delete the lines created by wizard from portapp.xml

file:

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

<property name="JSP" value="pagelat/ (jsp name).jsp"/>

then change the lines:

<component-profile>

<property name="tagLib"value="/SERVICE/htmlb/taglib/htmlb.tld"/>

</component-profile>

In JSP add as first line:

<%@ taglib url="tagLib"prefix="hbj"%>

hope this helps you to solve your problem.

If it helps you please let me know.

PS:Dont forget to reward points if you find its useful.

Regards

Victoria

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

You have made a small mistake, I believe this to be the reason.

public void doProcessBeforeOutput() throws PageException {


((IPortalComponentRequest)getRequest()).getServletRequest().setAttribute("myBean", myBean); 
myBean myBean = new myBean();
myBean.setName("bb");
this.setJspName("jsp2.jsp");
}

In this code myBean object is instantiated after setting it in the servlet request.

Please do it as below.This should solve your problem.

<b>myBean myBean = new myBean();

((IPortalComponentRequest)getRequest()).getServletRequest().setAttribute("myBean", myBean);

myBean.setName("bb");

this.setJspName("jsp2.jsp");

</b>

By the way , why are you using the same name for both the class and the object?

Regards,

Harish

(Please award points for helpful answers)

Message was edited by: HARISH SUBRAMANIAN

Message was edited by: HARISH SUBRAMANIAN

Former Member
0 Kudos

Hi,

Add d following line at d start of ur <b>jsp</b>.

<i><%@ taglib uri="tagLib" prefix = "hbj" %</i>>

Include the following piece of code in <b>portalapp.xml</b>.

<i><component-profile>

<property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld"/>

</component-profile></i>

Check if u've removed the following lines from ur <b>portalapp.xml</b>:

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

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

Hope this helps.

Regards,

M.Subathra