So, when you write <s:hidden name="backendsystems"/> you are asking Struts to
convert your list to a string and represent it like:
<input type="hidden" value="StringRepresentationofList"/>  and I am not sure
that is what you want.  Because when you resubmit that String struts is not
really sure how to rebuild the list.  

I see you have read up on type conversion and that is good.  The entry you
made in ShowUserAction-conversion.properties tells Struts what type of
object to create when it sees a list.  How does Struts see a list?  With
field names like <s:textfield name="backendsystems[0].id"/>  <s:textfield
name="backendsystems[0].name/>.  You can see where that is going.  You need
to build up the full representation of each Backend system as text or hidden
fields in order to recreate the list on the post.  Unless you really need to
show all that data as editable info or they are really small simple beans in
your list its a major Pain in the A%$#.  

So it really depends on what you are trying to do.  I can tell you that you
may not need the -conversion.properties entry when you are using Generics to
tell Struts the type of "things" in the List.  Let's assume that you only
need the conversion entry if the List is the old Object type and not typed
<BackendSystem>.   Then you can create a converter for BackendSystem *which
I suspect is what you really need.

If BackendSystem is persisted then you can represent each one as an id when
its a string (if you don't need to edit it) and then use the id to lookup
and "rehydrate" the object when going back from the webpage.  If it is not
persisted then you can create a String like "name~desc~prop1~" and then
parse it when its submitted to setup the object.  In both of these cases you
are creating a converter for BackendSystem and then with your list you do:

<s:hidden name="backendsystem[0]"/>  which when you are using ids will come
out as a number.

Sorry for the book, but I think Type Conversion is the least understood
feature of S2 and one of the most powerful.  Describe what you are trying to
do with your list and we can work out what pattern works best for you.



Henrik Strøm-Andersen wrote:
> 
> As new to Struts 2 I guess this is a simple question for you:
> 
> I have an action class (ShowUserAction) with a populated list: private
> List<Backend> backendsystems = new LinkedList<Backend>(); 
> 
> This action class has the usual public set, get and add methods for the
> list.
> 
> Among other string fields I want to transfer these list values as hidden
> in a form back to the action class:
> 
> <s:form action="showUserSave" method="POST">
>       ...
>       ...
>       <s:hidden name="backendsystems"/>
>       <s:submit value="Add"/>
> </s:form>
> 
> And I have made a ShowUserAction-conversion.properties:
> Element_backendsystems=Backend
> 
> But this does not work! The list is empty in the showUserSave method.
> 
> Henrik
> 

-- 
View this message in context: 
http://www.nabble.com/Type-conversion--tp21546300p21556516.html
Sent from the Struts - User mailing list archive at Nabble.com.


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

Reply via email to