cancel
Showing results for 
Search instead for 
Did you mean: 

JSP Bean communication problem

Former Member
0 Kudos

Hi,

I have one JSPDynpage and two JSPs. The first JSPs is a form that takes in a number of values. Upon clicking the button in the form, I have a bean that sets these form values in the doProcessAfterInput method. I have system.out.println's in a number of places and can see that these values are being set. However in the 2nd JSP, when I use the bean methods to get the values, they are all null. I've tried storing the beans in the portal's Context, Session and Profile. Why doesn't the 2nd JSP have access to the correct scope of the bean???

JSPDynpage code:

package com.waveset.spml.password;

import com.waveset.spml.password.idmSpmlBean;

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

public DynPage getPage() {

return new ChangePasswordDynPage();

}

public static class ChangePasswordDynPage extends JSPDynPage {

private final static int INITIAL_STATE = 0;

private final static int CHANGE_PASS_STATE = 1;

private int state = INITIAL_STATE;

private String idm_url = null;

private String idm_uid = null;

private String old_password = null;

private String new_password = null;

private String confirm_new_password = null;

private idmSpmlBean idmSpmlBean = null;

public ChangePasswordDynPage() {

}

public void doInitialization() {

System.out.println("In doInitialization()");

IPortalComponentRequest request =

(IPortalComponentRequest) this.getRequest();

IPortalComponentContext myContext = request.getComponentContext();

IPortalComponentProfile myProfile = myContext.getProfile();

IPortalComponentSession componentSession =

request.getComponentSession();

Object o = componentSession.getValue("idmSpmlBean");

if (o == null || !(o instanceof idmSpmlBean)) {

idmSpmlBean = new idmSpmlBean();

componentSession.putValue("idmSpmlBean", idmSpmlBean);

myContext.putValue("idmSpmlBean", idmSpmlBean);

componentSession.putValue("idmSpmlBean", idmSpmlBean);

} else {

idmSpmlBean = (idmSpmlBean) o;

}

state = INITIAL_STATE;

}

public void ButtonClicked(Event event) throws PageException {

System.out.println("In ButtonClicked() ");

state = CHANGE_PASS_STATE;

System.out.println(

"onButtonClicked changed state to CHANGE_PASS_STATE");

}

public void doProcessAfterInput() throws PageException {

System.out.println("In doProcessAfterInput");

IPortalComponentRequest request =

(IPortalComponentRequest) this.getRequest();

IPortalComponentContext myContext = request.getComponentContext();

IPortalComponentProfile myProfile = myContext.getProfile();

IPortalComponentSession componentSession =

request.getComponentSession();

//idmSpmlBean myBean = (idmSpmlBean) myContext.getValue("idmSpmlBean");

idmSpmlBean myBean =

(idmSpmlBean) componentSession.getValue("idmSpmlBean");

InputField idm_url_input =

(InputField) getComponentByName("idm_url_input");

if (idm_url_input != null) {

this.idm_url = idm_url_input.getValueAsDataType().toString();

myBean.setIdmUrl(idm_url);

}

InputField idm_uid_input =

(InputField) getComponentByName("idm_uid_input");

if (idm_uid_input != null) {

this.idm_uid = idm_uid_input.getValueAsDataType().toString();

myBean.setIdmUid(idm_uid);

}

InputField new_password_input =

(InputField) getComponentByName("new_password_input");

if (new_password_input != null) {

this.new_password =

idm_uid_input.getValueAsDataType().toString();

myBean.setNewPassword(new_password);

}

InputField old_password_input =

(InputField) getComponentByName("old_password_input");

if (old_password_input != null) {

this.old_password =

old_password_input.getValueAsDataType().toString();

myBean.setOldPassword(old_password);

}

InputField confirm_new_password_input =

(InputField) getComponentByName("confirm_new_password");

if (confirm_new_password_input != null) {

this.confirm_new_password =

confirm_new_password_input.getValueAsDataType().toString();

myBean.setConfirmNewPassword(confirm_new_password);

}

}

public void doProcessBeforeOutput() throws PageException {

System.out.println("In doProcessBeforeOutput()");

if (state == INITIAL_STATE) {

this.setJspName("changePassword.jsp");

} else {

this.setJspName("passwordChange.jsp");

}

}

}

}

The first JSP is just a form, but here is the 2nd JSP:

<%@ page language="java" %>

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

<jsp:useBean id="idmspmlBean" scope="session" class="com.waveset.spml.password.idmSpmlBean" />

<hbj:content id="myContext2" >

<hbj:page title="PageTitle2">

<hbj:form id="myFormId2" >

<hbj:textView

id="message1"

design="HEADER1" >

<% message1.setText("uid = " + idmspmlBean.getIdmUid());

%>

</hbj:textView>

<p>

<p>

<hbj:textView

id="message2"

design="HEADER1" >

<% message2.setText("url = " + idmspmlBean.getIdmUrl());

%>

</hbj:textView>

<p>

<p>

<hbj:textView

id="message3"

design="HEADER1" >

<% message3.setText("old password = " + idmspmlBean.getOldPassword());

%>

</hbj:textView>

<p>

<p>

<hbj:textView

id="message4"

design="HEADER1" >

<% message4.setText("New Password = " + idmspmlBean.getNewPassword());

%>

</hbj:textView>

<p>

<p>

</hbj:form>

</hbj:page>

</hbj:content>

All of these values print out null.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

My setMethods are setting the correct value, however my get methods are always returning null.

MartyMcCormick
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Vu,

Have you tried setting the iView isolation method to URL vs embedded? We had a similar problem last week with beans returning null (but working on the component preview) and this was the solution.

Hope this helps,

Marty

Former Member
0 Kudos

In my portalapp.xml, I set

<component-profile>

<property name="com.sap.portal.reserved.iview.IsolationMode" value="URL">

And that didn't work. I am testing the JSP/Bean communication with the UserNameBean example from the PDK. If I cannot get even the sample to work, how is one to do any real development on EP6?

MartyMcCormick
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Vu,

What does your portalapp.xml look like, can you paste it in?

Also, if you create a getter method in your bean with a static value, does it correctly return this value to your 2nd JSP?

Marty

Former Member
0 Kudos

Hi Marty,

Here is my portalapp.xml file:

<?xml version="1.0" encoding="utf-8"?>

<application>

<application-config>

<property name="PrivateSharingReference" value="com.sap.portal.htmlb"/>

<property name="SharingReference" value="htmlb"/>

</application-config>

<components>

<component name="DynPageOne">

<component-config>

<property name="ClassName" value="com.mycompany.basicexample.DynPageOne"/>

<property name="SecurityZone" value="com.mycompany.basicexample.DynPageOne/low_safety"/>

</component-config>

<component-profile>

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

<property name="com.sap.portal.reserved.iview.IsolationMode" value="URL"/>

</component-profile>

</component>

</components>

<services/>

</application>

I also created a getter method in my bean to return a static value and that value is returned correctly. Any more ideas?

MartyMcCormick
Product and Topic Expert
Product and Topic Expert
0 Kudos

I noticed that when you call the get the bean's context from the Java class, you use:


idmSpmlBean myBean =
(idmSpmlBean) componentSession.getValue("idmSpmlBean");

Yet, when calling from the 2nd JSP you are giving it an ID=idmspmlBean.


jsp:useBean id="idmspmlBean" scope="session" class="com.waveset.spml.password.idmSpmlBean" />

Not 100% positive, but I think the class and the JSP need to be using the same IDs. In the class you used a capital Spml, the JSP you used a lowercase spml.

Hope this helps,

Marty

Former Member
0 Kudos

Hi Vu,

Is this the portalapp.xml for the code you have posted?

Former Member
0 Kudos

Hi Marty,

GASP It worked!!!

Who knew that EP6 could be so stringent on JSP Bean and DynPage Bean IDS...

Thanks for all your help. Woooopeeeee!!!!

Answers (3)

Answers (3)

Former Member
0 Kudos

Yes, I have tried with scope=application and session.

I have the same problem as when I try it with the BasicExample in the JSPDynpage sample from the PDK.

Problem is similar to this thread:

System.out.println()'s indicate the values are being set, however when they're read in to the JSP, they are NULL.

Former Member
0 Kudos

Hi Vu,

did u change the scope to "application" instead of "session" in <jsp:useBean id="idmspmlBean" scope="session" >. As well put system.out.println statements in bean also. Check the values while setting the bean values and while calling the bean values. Check whether null values are not stored in the bean.

Thanks,

Praveen

Former Member
0 Kudos

Hi Vu,

Many of us have answered your issues and if you think that your problem is solved, you are supposed to give points to the members. Till now you havent assigned any points. Remember to do this by clicking on the yellow star.

Coming to your issue, Trying printing your values to console using system.out.println after clicking on submit button. Check the values whether you can get them in program. As well in <jsp:useBean id="idmspmlBean" scope="session" class="com.waveset.spml.password.idmSpmlBean" />

change the scope from "session" to "application" and check.

Regards,

Praveen

Former Member
0 Kudos

Hi Praveen,

Thanks for the tip, I wasn't sure how to give points before. I have System.out.println()'s in several places and I have checked what the values of these variables are once I have clicked the buttons. The values are correct. It's when I get to the 2nd JSP the values are null. Any other tips?

-Vu