struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Lindholm <glindh...@yahoo.com>
Subject Re: Struts 2 - Dynamic form: submitting issues
Date Mon, 30 Mar 2009 13:08:17 GMT



Timmos wrote:
> 
> Hi,
> 
> I figured out how to generate a form with dynamic length. The submitting
> part remains a bit tricky, but before you redirect me to OGNL / Type
> Conversion pages, I have to say I already read those articles.
> 
> This is a part of my generated .jsp (the generate part - I won't include
> the Action code for this):
> 
> <s:iterator value="properties" status="stat">
>     <s:textfield name="lijst[2]" label="%{name}" />
> </s:iterator>
> 
> As you can see, for testing purposes I hard-coded the index "2", but I
> don't know if this syntax is correct.
> 
> This form is to be submitted to DoSearchAction:
> 
> public void setLijst(int index, String s) {
>      lijst[index] = s;
>      System.out.println(">>>> LIJST!!! >> " + index + ":::" + s);
> }
> 
> When I run this piece of junk, I get: ognl.OgnlException: target is null
> for setProperty(null, "2", [Ljava.lang.String;@13dd8).
> 
> I would like to know what is wrong with the setter / s:textfield name
> parameter. What do I have to do to get it working?
> 
> 
> 

This will work. You just have to provide getter and setter for your list.

<s:iterator value="myList" status="stat">
    <s:textfield name="myList[%{#stat.index}].field1" />
    <s:textfield name="myList[%{#stat.index}].field2" />
</s:iterator>

    public List<MyClass> getMyList()
    {
        return myList;
    }
    public void setMyList(List<MyClass>myList)
    {
        this.myList = myList;
    }

-- 
View this message in context: http://www.nabble.com/Struts-2---Dynamic-form%3A-submitting-issues-tp22755036p22782850.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Mime
View raw message