You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by kukudas <ku...@googlemail.com> on 2008/06/12 15:34:12 UTC

Struts 2 s:select question

hi,

basicly i can't find any working example, howto set the value which was
choosen into a variable so i can use this in my beans. i've tryied using the
namespace which didn't work.
someone can provide me with an working example would be awesome thanks.

greets

kuku
-- 
View this message in context: http://www.nabble.com/Struts-2-s%3Aselect-question-tp17800089p17800089.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


Re: Struts 2 s:select question

Posted by Martin <mg...@hotmail.com>.
Can you supply the
jsp sepecifically looking for s:select
web.xml
struts<-config>.xml
as well as the code from Action class

http://struts.apache.org/2.0.11.1/docs/select.html

Thanks
Martin
----- Original Message ----- 
From: "kukudas" <ku...@googlemail.com>
To: <us...@struts.apache.org>
Sent: Thursday, June 12, 2008 9:34 AM
Subject: Struts 2 s:select question


>
> hi,
>
> basicly i can't find any working example, howto set the value which was
> choosen into a variable so i can use this in my beans. i've tryied using 
> the
> namespace which didn't work.
> someone can provide me with an working example would be awesome thanks.
>
> greets
>
> kuku
> -- 
> View this message in context: 
> http://www.nabble.com/Struts-2-s%3Aselect-question-tp17800089p17800089.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
>
> 


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


Re: Struts 2 s:select question

Posted by Ralf Fischer <th...@googlemail.com>.
Hi,

On Thu, Jun 12, 2008 at 4:30 PM, kukudas <ku...@googlemail.com> wrote:
> Hi, thanks for your reply i think i did it right but still getting an
> exception:
> this is how it works when i do a textfield and enter the value by my hand:
> <s:textfield id="athy" label="Rolle" name="a.Auth"/>
>
> And this is when i try doing it with the s:select
> <s:select name="a.Auth" list="authorities" label="Choose" listValue="athy"/>
>
> i have getter/setter for a in my ActionClass. a is a Object from another
> Class lets call it Athy. authorities is a list in my ActionClass which has
> getter/setter too. and athy is the string from the Class Athy(where i make
> the "a" object from). the list and listValue thing is working because i get
> the right values populated the thing which doesnt work is the name attribute
> "a.Auth". Its Strange that in a textfield when i send the value it works ..
>
> The items in the list are populated but when i select something and push
> submit i get this error:
> java.util.NoSuchElementException

Well, that's straight forward: When you press submit the browser only
sends the string representation of the object to the server. As, I'm
pretty sure, you don't have any type conversion of the value set in
the select box to the type of your property in the action, which
should be setA(Athy). You now have some options:

a) Check out how type conversion works within struts2/xwork [1] and
write an appropriate type converter. This options is only viable from
my point of view when Arty is just a simple class and no entity. I
think reading entities from the database or taking similar actions in
a type converter is no good practice, but I might be wrong here.

b) Intercept the action invocation on the way and create/inject the
object from the interceptor into the action, maybe with some
annotation or interface on the action class which marks for the
interceptor to take action on this invocation.

c) Set the String parameter which was selected into the action (by
providing an appropriate setter taking a String) and do the work of
converting the action there. I usually discourage from this, as
conversion code does IMO not belong to the action.

Bye
-Ralf

[1] http://struts.apache.org/2.x/docs/type-conversion.html

> Jim Kiley wrote:
>>
>> The s:select tag doesn't have much to do with the namespace.
>>
>> What you'll want to do is something like this:
>>
>> <s:form action="myAction">
>> <s:select name="myProperty" list="backingList" listKey="field1"
>> listValue="field2" label="Choose a thing"/>
>> <s:submit />
>> </s:form>
>>
>> Then you just have to make sure that your action ('myAction') has getters
>> and setters for 'myProperty', a getter for 'backingList', and that each
>> element of 'backingList' has fields 'field1' and 'field2', both of which
>> have public getters.
>>
>> Does this help?
>>
>> jk
>>
>> On Thu, Jun 12, 2008 at 9:34 AM, kukudas <ku...@googlemail.com> wrote:
>>
>>>
>>> hi,
>>>
>>> basicly i can't find any working example, howto set the value which was
>>> choosen into a variable so i can use this in my beans. i've tryied using
>>> the
>>> namespace which didn't work.
>>> someone can provide me with an working example would be awesome thanks.
>>>
>>> greets
>>>
>>> kuku
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Struts-2-s%3Aselect-question-tp17800089p17800089.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
>>>
>>>
>>
>>
>> --
>> Jim Kiley
>> Technical Consultant | Summa
>> [p] 412.258.3346 [m] 412.445.1729
>> http://www.summa-tech.com
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Struts-2-s%3Aselect-question-tp17800089p17801387.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
>
>

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


Re: Struts 2 s:select question

Posted by kukudas <ku...@googlemail.com>.
Hi, thanks for your reply i think i did it right but still getting an
exception:
this is how it works when i do a textfield and enter the value by my hand:
<s:textfield id="athy" label="Rolle" name="a.Auth"/>

And this is when i try doing it with the s:select
<s:select name="a.Auth" list="authorities" label="Choose" listValue="athy"/>

i have getter/setter for a in my ActionClass. a is a Object from another
Class lets call it Athy. authorities is a list in my ActionClass which has
getter/setter too. and athy is the string from the Class Athy(where i make
the "a" object from). the list and listValue thing is working because i get
the right values populated the thing which doesnt work is the name attribute
"a.Auth". Its Strange that in a textfield when i send the value it works ..
 
The items in the list are populated but when i select something and push
submit i get this error:
java.util.NoSuchElementException



Jim Kiley wrote:
> 
> The s:select tag doesn't have much to do with the namespace.
> 
> What you'll want to do is something like this:
> 
> <s:form action="myAction">
> <s:select name="myProperty" list="backingList" listKey="field1"
> listValue="field2" label="Choose a thing"/>
> <s:submit />
> </s:form>
> 
> Then you just have to make sure that your action ('myAction') has getters
> and setters for 'myProperty', a getter for 'backingList', and that each
> element of 'backingList' has fields 'field1' and 'field2', both of which
> have public getters.
> 
> Does this help?
> 
> jk
> 
> On Thu, Jun 12, 2008 at 9:34 AM, kukudas <ku...@googlemail.com> wrote:
> 
>>
>> hi,
>>
>> basicly i can't find any working example, howto set the value which was
>> choosen into a variable so i can use this in my beans. i've tryied using
>> the
>> namespace which didn't work.
>> someone can provide me with an working example would be awesome thanks.
>>
>> greets
>>
>> kuku
>> --
>> View this message in context:
>> http://www.nabble.com/Struts-2-s%3Aselect-question-tp17800089p17800089.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
>>
>>
> 
> 
> -- 
> Jim Kiley
> Technical Consultant | Summa
> [p] 412.258.3346 [m] 412.445.1729
> http://www.summa-tech.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts-2-s%3Aselect-question-tp17800089p17801387.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


Re: Struts 2 s:select question

Posted by Jim Kiley <jh...@summa-tech.com>.
The s:select tag doesn't have much to do with the namespace.

What you'll want to do is something like this:

<s:form action="myAction">
<s:select name="myProperty" list="backingList" listKey="field1"
listValue="field2" label="Choose a thing"/>
<s:submit />
</s:form>

Then you just have to make sure that your action ('myAction') has getters
and setters for 'myProperty', a getter for 'backingList', and that each
element of 'backingList' has fields 'field1' and 'field2', both of which
have public getters.

Does this help?

jk

On Thu, Jun 12, 2008 at 9:34 AM, kukudas <ku...@googlemail.com> wrote:

>
> hi,
>
> basicly i can't find any working example, howto set the value which was
> choosen into a variable so i can use this in my beans. i've tryied using
> the
> namespace which didn't work.
> someone can provide me with an working example would be awesome thanks.
>
> greets
>
> kuku
> --
> View this message in context:
> http://www.nabble.com/Struts-2-s%3Aselect-question-tp17800089p17800089.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
>
>


-- 
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com