Have your Action method getAuthorizedOptions() return something like a Hashtable<String,MyBean>, where MyBean is your inner thingy with methods setWhateverProperty() and getWhateverProperty(). Then your iterator incantation as below:

<s:iterator value="authorizedOptions" id="o">

would deliver instances of Hashtable.Entry<String,MyBean>, which means that you would be able to access the dynamic current String value as "key" and would be able to call the MyBean method via value.whateverProperty. So far this is pretty standard s:iterator talk. Now things get a bit more complex, but Martin was correct in his example, but maybe the following is closer to what you need:

<s:iterator value="authorizedOptions" id="o">
<s:textfield label="Person %{key}" name="authorizedOptions['%{key}'].whateverProperty" />
</s:iterator>

The magic is in the "name" property, which maps to dynamic calls to YourActionClass.getAuthorizedOptions(keyValue).getWhateverProperty() and YourActionClass.getAuthorizedOptions(keyValue).setWhateverProperty() for each keyValue that was added to your Hashtable when you popuplated it from wherever your data came from.

Does this help?

Robert

Am 04.05.2010 15:20, schrieb Mitch Claborn:
I could probably restructure my data to make it fit that model, but that is not the ideal solution. My data is structured more like a hash, where the keys are essentially arbitrary and unpredictable. Is there something similar that would work with that kind of structure?

Mitch


Martin Gainty wrote:
//The action class contains a (dynamically populated) collection such as persons defined here

@Result(name="list", value="listPeople.action", type=ServletRedirectResult.class)
public class EditPersonAction extends ActionSupport {
    ArrayList<Person> persons = new ArrayList()
<snip>
}

//then the jsp makes reference to persons ArrayList from the action class and references specific rows by utilising stat.index by the s:iterator iterator

<s:form action="submitPersonInfo" namespace="/conversion" method="post">
<%--
        The following is done Dynamically
    --%>
<s:iterator value="new int[3]" status="stat">
<s:textfield label="%{'Person '+#stat.index+' Name'}" name="%{'persons['+#stat.index+'].name'}" /> <s:textfield label="%{'Person '+#stat.index+' Age'}" name="%{'persons['+#stat.index+'].age'}" />
</s:iterator>

this would achieve the effect of dynamically populating n number of Person objects

does this answer the question?
Martin Gainty ______________________________________________ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




Date: Mon, 3 May 2010 09:08:29 -0500
From: mi...@claborn.net
To: user@struts.apache.org
Subject: Re: input fields with dynamic names

Bump.  Any other ideas?

mitch


Mitch Claborn wrote:
That works for setting parameter names, but not so well when the tags in the JSP need to retrieve the value for display in the page, particularly if there is a validation error. If there is a static field named "fred" and the action has a "getFred()" method, then all is good. But the field names in my case are dynamic, so I can't have a getNNNNN for all of the dynamic fields.

mitch


Greg Lindholm wrote:
You are probably looking for ParameterAware

http://struts.apache.org/2.x/struts2-core/apidocs/org/apache/struts2/interceptor/ParameterAware.html


On Wed, Apr 28, 2010 at 12:47 PM, Mitch Claborn <mi...@claborn.net> wrote:

I'm sure I've seen the answer to this somewhere, but darned if I can find it
now when I need it!

I have a page that allows edits of various options, the names of which are dynamically retrieved from the database. If I have the code in the JSP as
below, the value displayed in the text field is always that from the
database. If there is a validation error, the user's input value is not maintained as it would be if there were an explicit getter/setter for each option name. Is there a way to code the Action (or the JSP) so that the
value shown is the user's input value if there is an error?

<s:iterator value="authorizedOptions" id="o">
<s:textfield size="10" name="${o.optionName}"
id="${o.optionName}" value="${o.valueInt}" />

Mitch


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


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


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


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

_________________________________________________________________ The New Busy is not the old busy. Search, chat and e-mail from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3

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






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

Reply via email to