You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mitch Claborn <mi...@claborn.net> on 2011/05/11 21:03:33 UTC

Retrieving values for which there is no specific getter

In Struts 2, if my Action class has a variable named "fred" and a getter 
"getFred()", a <s:textfield name="fred" /> will call that getter to 
retrieve the value from the action.

Is there some kind of catch-all or generic method that is called to 
retrieve the value for a form field if there is no specific getter?  For 
example, I might have
<s:textfield name="fred1" />
<s:textfield name="fred2" />
...
<s:textfield name="fred100" />

I don't want to code a specific getter for each one.

I thought I saw some documentation on the sequence of methods that are 
attempted, but can't find it now.

Mitch

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


Re: Retrieving values for which there is no specific getter

Posted by Mitch Claborn <mi...@claborn.net>.
If my action has "map" and getter getMap(), how would I specify the 
name= field in my struts tags to fetch specific values from the map?

<s:textfield name="map???what goes here??" />


Mitch


On 05/11/2011 02:32 PM, Dave Newton wrote:
> Not sure how to elaborate on using a map. Expose a map, use whatever
> key makes sense? Iterate over the keys using whatever comparator you
> need? What do you want to know?
>
> Dave

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


Re: Retrieving values for which there is no specific getter

Posted by Dave Newton <da...@gmail.com>.
On Wed, May 11, 2011 at 3:29 PM, Mitch Claborn wrote:
> Can you elaborate a bit?  My values will not necessarily be sequential.

Not sure how to elaborate on using a map. Expose a map, use whatever
key makes sense? Iterate over the keys using whatever comparator you
need? What do you want to know?

Dave

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


Re: Retrieving values for which there is no specific getter

Posted by Mitch Claborn <mi...@claborn.net>.
Can you elaborate a bit?  My values will not necessarily be sequential.

mitch


On 05/11/2011 02:14 PM, Dave Newton wrote:
> On Wed, May 11, 2011 at 3:03 PM, Mitch Claborn wrote:
>> Is there some kind of catch-all or generic method that is called to retrieve
>> the value for a form field if there is no specific getter?
>
> No, but you could use a map, or a collection if they're sequential as you show.
>
> Dave

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


Re: Retrieving values for which there is no specific getter

Posted by Dave Newton <da...@gmail.com>.
On Wed, May 11, 2011 at 3:03 PM, Mitch Claborn wrote:
> Is there some kind of catch-all or generic method that is called to retrieve
> the value for a form field if there is no specific getter?

No, but you could use a map, or a collection if they're sequential as you show.

Dave

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


Re: Retrieving values for which there is no specific getter

Posted by Chris Pratt <th...@gmail.com>.
You implement the ParameterAware interface on your Action.  Struts calls
your action's setParameters(Map) method passing you the map of all the
parameters that were submitted by the form.  You use the map in your
action's execute() method to fulfill it's reason for being.
  (*Chris*)

On Wed, May 11, 2011 at 12:28 PM, Mitch Claborn <mi...@claborn.net>wrote:

> I think the ParameterAware is for setting values into my Action.  I need to
> get the values from my action, into the HTML form.
>
> mitch
>
>
>
> On 05/11/2011 02:07 PM, Chris Pratt wrote:
>
>> Not as such, but you can implement the ParameterAware[1] interface and
>> retrieve the from the supplied map.
>>   (*Chris*)
>>
>> 1 -
>>
>> http://struts.apache.org/2.0.6/struts2-core/apidocs/org/apache/struts2/interceptor/ParameterAware.html
>>
>> On Wed, May 11, 2011 at 12:03 PM, Mitch Claborn<mitch_ml@claborn.net
>> >wrote:
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Retrieving values for which there is no specific getter

Posted by Mitch Claborn <mi...@claborn.net>.
I think the ParameterAware is for setting values into my Action.  I need 
to get the values from my action, into the HTML form.

mitch


On 05/11/2011 02:07 PM, Chris Pratt wrote:
> Not as such, but you can implement the ParameterAware[1] interface and
> retrieve the from the supplied map.
>    (*Chris*)
>
> 1 -
> http://struts.apache.org/2.0.6/struts2-core/apidocs/org/apache/struts2/interceptor/ParameterAware.html
>
> On Wed, May 11, 2011 at 12:03 PM, Mitch Claborn<mi...@claborn.net>wrote:
>

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


Re: Retrieving values for which there is no specific getter

Posted by Chris Pratt <th...@gmail.com>.
Not as such, but you can implement the ParameterAware[1] interface and
retrieve the from the supplied map.
  (*Chris*)

1 -
http://struts.apache.org/2.0.6/struts2-core/apidocs/org/apache/struts2/interceptor/ParameterAware.html

On Wed, May 11, 2011 at 12:03 PM, Mitch Claborn <mi...@claborn.net>wrote:

> In Struts 2, if my Action class has a variable named "fred" and a getter
> "getFred()", a <s:textfield name="fred" /> will call that getter to retrieve
> the value from the action.
>
> Is there some kind of catch-all or generic method that is called to
> retrieve the value for a form field if there is no specific getter?  For
> example, I might have
> <s:textfield name="fred1" />
> <s:textfield name="fred2" />
> ...
> <s:textfield name="fred100" />
>
> I don't want to code a specific getter for each one.
>
> I thought I saw some documentation on the sequence of methods that are
> attempted, but can't find it now.
>
> Mitch
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>