You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by James Navin <jn...@csc.com> on 2007/04/17 07:49:01 UTC

Map-backed forms in Struts2

Hi all,

A system I am developing requires forms to be generated dynamically at
runtime based on data stored in a database. I have read that it is possible
to use map-backed forms in Struts1 to achieve this using something of the
form '<s:textfield name="value(#currentField.fieldName)"/>' where the
associated Action class has a method of the form 'public void
setValue(String key, Object value)', resulting in name-value pairs being
submitted to the Action class.

Is this possible to achieve in Struts2? I have not been able to make it
work. When I use the above expression for the name attribute the setValue
method is never called (I have checked this with a few debug print
statements), but no exception is thrown either. It just appears that
nothing happens.

Is this something I am doing wrong, or is there some other way to do this
in Struts2, or is it a bug?

I am using Struts 2.0.6 with Java 1.5.3, Tomcat 5.5 and Internet Explorer
6.

Thanks a lot in advance,

James


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Map-backed forms in Struts2

Posted by James Navin <jn...@csc.com>.
Ok. I read the OGNL spec and it looks like the way of using maps etc. is
subtley different from Struts1. My JSP now looks like

<s:textfield name="attribute[#currentField.fieldname]"/>

and the associated Action class has methods

public void setAttribute(String key, Object value)
public Object getAttribute(String key)

The setAttribute method is still not being called (again, I have checked
with debug print statements), but this time in the catalina log I get the
following excepion messages along with a large stack trace

--snip--
Apr 18, 2007 9:57:01 AM
com.opensymphony.xwork2.util.InstantiatingNullHandler nullPropertyValue
SEVERE: Could not create and/or set value back on to object
ognl.NoSuchPropertyException:
com.csc.event.delivery.controller.EventOverviewController.attribute
[java.lang.IllegalAccessException: Class ognl.OgnlRuntime can not access a
member of class com.csc.event.delivery.controller.EventOverviewController
with modifiers "private"]
--snip--

It looks like it wants the actual attribute member to be public, but I
really dont want to do that...

Any help is much appreciated,

James

Lance <la...@marketpipe.com> wrote on 17/04/2007 06:54:37 PM:

> Do you have a getValue(String key) method?
> I am not a s2 user but I have read the OGNL spec so sorry if I'm wrong
> but OGNL needs
>    public PropertyType getPropertyName(IndexType index)
>    and public void setPropertyName(IndexType index, PropertyType value)
>
> http://www.ognl.org/2.6.9/Documentation/html/LanguageGuide/indexing.
> html#N10189
>
> James Navin wrote:
> > Hi all,
> >
> > A system I am developing requires forms to be generated dynamically at
> > runtime based on data stored in a database. I have read that it is
possible
> > to use map-backed forms in Struts1 to achieve this using something of
the
> > form '<s:textfield name="value(#currentField.fieldName)"/>' where the
> > associated Action class has a method of the form 'public void
> > setValue(String key, Object value)', resulting in name-value pairs
being
> > submitted to the Action class.
> >
> > Is this possible to achieve in Struts2? I have not been able to make it
> > work. When I use the above expression for the name attribute the
setValue
> > method is never called (I have checked this with a few debug print
> > statements), but no exception is thrown either. It just appears that
> > nothing happens.
> >
> > Is this something I am doing wrong, or is there some other way to do
this
> > in Struts2, or is it a bug?
> >
> > I am using Struts 2.0.6 with Java 1.5.3, Tomcat 5.5 and Internet
Explorer
> > 6.
> >
> > Thanks a lot in advance,
> >
> > James
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Map-backed forms in Struts2

Posted by Lance <la...@marketpipe.com>.
Do you have a getValue(String key) method?
I am not a s2 user but I have read the OGNL spec so sorry if I'm wrong 
but OGNL needs
   public PropertyType getPropertyName(IndexType index)
   and public void setPropertyName(IndexType index, PropertyType value)

http://www.ognl.org/2.6.9/Documentation/html/LanguageGuide/indexing.html#N10189

James Navin wrote:
> Hi all,
>
> A system I am developing requires forms to be generated dynamically at
> runtime based on data stored in a database. I have read that it is possible
> to use map-backed forms in Struts1 to achieve this using something of the
> form '<s:textfield name="value(#currentField.fieldName)"/>' where the
> associated Action class has a method of the form 'public void
> setValue(String key, Object value)', resulting in name-value pairs being
> submitted to the Action class.
>
> Is this possible to achieve in Struts2? I have not been able to make it
> work. When I use the above expression for the name attribute the setValue
> method is never called (I have checked this with a few debug print
> statements), but no exception is thrown either. It just appears that
> nothing happens.
>
> Is this something I am doing wrong, or is there some other way to do this
> in Struts2, or is it a bug?
>
> I am using Struts 2.0.6 with Java 1.5.3, Tomcat 5.5 and Internet Explorer
> 6.
>
> Thanks a lot in advance,
>
> James
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org