struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From 928572663 <>
Subject Re: session based pojo as form variables
Date Wed, 17 Sep 2008 21:41:42 GMT
I tried both suggestions and neither worked.

The first thing I tried was to implement the getter/setters and change 
the JSP as you suggested.   When I did this I got the following:

Caused by: ognl.OgnlException: formBean [java.lang.NullPointerException]
         at ognl.OgnlRuntime.getMethodValue(
         at ognl.OgnlRuntime.getProperty(
         ... 145 more

Then I tried adding the SessionAware interface.   The SessionAware 
interface requires me to implement this function:

    public void setSession(Map<String, Object> session)
       session.put("formBean", formBean);

however, when the interceptor calls setSession()  my formBean object 
hasn't been initialized yet, because the displayForm() action function 
hasn't been called yet.  This is the function that creates the pojo form 

Gabriel Belingueres wrote:
> I've never used a form field name like "#session.formBean.firstName"
> before, but if you refactor your code a little:
> Make your action implement SessionAware interface and put a formBean
> getter/setter in your actions (or some superclass of your wizard
> actions), which takes it from the session:
> public FormBean getFormBean() {
>   return (FormBean) sessionMap.get("formBean");
> }
> public void setFormBean(FormBean f) {
>   sessionMap.put("formBean", f);
> }
> then in your JSP page name your form fields like this:
> <s:textfield name="formBean.firstName" label="First Name" size="16" />

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message