struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From str...@jtheory.com
Subject repopulating fields from an array in a formbean
Date Wed, 05 Jul 2006 22:20:07 GMT
I have two related questions...  I can probably figure out ways to hack
around these issues, but I'm hoping for a "best practices" solution.

My requirement is pretty simple: you click on a category link, the
action builds the List of items for that category, and the JSP iterates
them and shows quantity input fields using <html:text
property="quantity"/>.  That's fine.  It matches up with a String[]
quantity property in the formbean class (I'm not using dynabeans).  The
user enters quantities, and clicks the "Add to Order" submit button.  If
the quantities they entered pass formbean validation, the items get
added.  If they fail validation, the item list displays again (with
their quantity entries repopulated).

The validation error handling is where I'm stuck.  If the form bean
validate() method fails, Struts automatically shows the input (the item
listing action)... but:
1) How do I reload the item listing page with the right category info? 
I managed to get this working for now by putting the categoryId in a
hidden field on the page (submitting to a form that doesn't actually
need it... seems like a hack, but it works).
2) How can I repopulate the quantity input fields (all with name
"quantity") with the right value?  Struts populates the fields with
"[Ljava.lang.String;@36947bbe" -- the whole array, apparently, instead
of the right element.

#2 is the most important one, since it seems like there must be a
straightforward way to do this in Struts... if arrays work for incoming
params, there must be a way to use them for form repopulation, right?

Thanks for any suggestions!
Rob W.

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


Mime
View raw message