struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From 928572663 <928572...@cox.net>
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(OgnlRuntime.java:935)
         at 
ognl.ObjectPropertyAccessor.getPossibleProperty(ObjectPropertyAccessor.java:53)
         at 
ognl.ObjectPropertyAccessor.getProperty(ObjectPropertyAccessor.java:121)
         at 
com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.getProperty(ObjectAccessor.java:17)
         at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1643)
         at 
com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.getProperty(CompoundRootAccessor.java:116)
         ... 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 
bean.




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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message