struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <lau...@holoweb.net>
Subject Re: Struts 2 <s:select> tag : Unable to retrieve the value in theaction
Date Tue, 29 Apr 2008 17:03:27 GMT
 > <----- Start JSP ----->
 > <s:select value="selectKeyword" theme="simple" key="selectKeyword"
 > id="selectKeyword" name="selectKeyword" list="selectKeyword"
 > multiple="true"></s:select>
 > <----- End JSP ----->

You've specified 'selectKeyword' for every attribute... Each of those 
attributes has a different meaning, so this wont work.

You need two properties on your action:

1) a collection of possible choices for the user to select from
2) a collection of values that have been selected

In the s:select tag, you need to set:

   'name' (or 'key') to the property that will record what was selected
   'list' to the property that contains all possible choices

If the property you specify in the 'list' attribute is a Map (as you 
said in your first post) that's it. If it's not a map, you'll probably 
need to also specify 'listKey' and 'listValue'.

Here's an example (not tested):

- action code:

   public Map getAvailableKeywords() { ... }

   public List getSelectedKeywords() { ... }
   public void setSelectedKeywords(List selected) { ... }

- JSP code:

   <s:select name="selectedKeywords list="availableKeywords"/>

HTH,

L.


Binu John wrote:
> This does not help. :(
> I tried using the setter method as below
> 
>         void setSelectKeyword(String[] selectKeyword) {
>         log.debug(LoginAction.class.getName() + ": execute() : Checkpoint 1");
>         this.temp = selectKeyword;
>     }
> 
> But the log statement even does not gets printed. That means that the setter is not even
getting called.
> Also in the code fragment that you suggested, you specified that "selectedKeyword is
what is selected". How do we configure that?
> Do we have to set some parameter to make sure that the values in the list are getting
written back using the setter?
> 
> -----Original Message-----
> From: pandamouse@hotmail.com [mailto:pandamouse@hotmail.com]
> Sent: Tuesday, April 29, 2008 6:47 AM
> To: Binu John
> Subject: Struts 2 <s:select> tag : Unable to retrieve the value in theaction
> 
> 1. Make sure all the options you want are selected. (e.g. if your selectKeyword list
contains all the entry that you want to be selected then make sure they are all highlighted
when you submit the form <maybe via a javascript>).
> 2. Try getting it back as an Array of something instead.
> 
> i.e. (assuming 1. doesn't apply. I have selectKeyword as the source to select from and
selectedKeyword which is what is selected)
> private String[] selectedKeyword;
> public void setSelectedKeyword(String[] selectedKeyword) {
>          log.debug(LoginAction.class.getName() + ": execute() : HERE
>  AFASDFSD");
>          this.selectedKeyword = selectedKeyword;
>  }
> 
> public String saveKeyword()
> {
>          System.out.println("selectedKeywords:" +
>  selectedKeyword);
>  }
> 
> Hope that helps.
> 
> Binu John wrote:
>>
>> Hi,
>> I am trying to use the select tag and somehow it does not work as
>> expected.
>> I am populating a Map with the desired values and using that Map object in
>> the select tag.
>>
>> <----- Start JSP ----->
>> <s:select value="selectKeyword" theme="simple" key="selectKeyword"
>> id="selectKeyword" name="selectKeyword" list="selectKeyword"
>> multiple="true"></s:select>
>> <----- End JSP ----->
>>
>> <----- Start Action Code ----->
>> private Map selectKeyword = new HashMap();
>> public void setSelectKeyword(Map selectKeyword) {
>>         log.debug(LoginAction.class.getName() + ": execute() : HERE
>> AFASDFSD");
>>         this.selectKeyword = selectKeyword;
>> }
>> public Map getSelectKeyword() {
>>         return selectKeyword;
>> }
>>
>> public String execute()
>> {
>>         selectKeyword = populateHashMap();
>>         return SUCCESS;
>> }
>> /* This gets called when I submit the form */
>> public String saveKeyword()
>> {
>>         System.out.println("This prints size as 0 : " +
>> selectKeyword.size());
>> }
>> <----- End Action Code ----->
>>
>> I am able to view the populated list box but when I try to retrieve the
>> value back in my code, I am not getting any value.
>>
>> Any idea where I am going wrong?
>>
>> Binu John
>> Programmer Analyst,
>> Infosys Technologies Limited, Pune
>> Mobile # +919823019001
>>
>>
>> **************** CAUTION - Disclaimer *****************
>> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended
>> solely for the use of the addressee(s). If you are not the intended
>> recipient, please notify the sender by e-mail and delete the original
>> message. Further, you are not to copy, disclose, or distribute this e-mail
>> or its contents to any other person and any such actions are unlawful.
>> This e-mail may contain viruses. Infosys has taken every reasonable
>> precaution to minimize this risk, but is not liable for any damage you may
>> sustain as a result of any virus in this e-mail. You should carry out your
>> own virus checks before opening the e-mail or attachment. Infosys reserves
>> the right to monitor and review the content of all messages sent to or
>> from this e-mail address. Messages sent to or from this e-mail address may
>> be stored on the Infosys e-mail system.
>> ***INFOSYS******** End of Disclaimer ********INFOSYS***
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
> Quoted from:
> http://www.nabble.com/Struts-2-%3Cs%3Aselect%3E-tag-%3A-Unable-to-retrieve-the-value-in-the-action-tp16940747p16940747.html


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


Mime
View raw message