Skip to Content
author's profile photo
Former Member

JSP Bean communication problem

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.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Jan 18, 2005 at 09:07 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Jan 15, 2005 at 03:44 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo
    Former Member
    Posted on Jan 18, 2005 at 06:09 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Jan 18, 2005 at 07:27 PM

    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:

    cannot-get-a-simple-jspdynpage-working

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

    Add comment
    10|10000 characters needed characters exceeded