Pre select a button in struts 2

Go To StackoverFlow.com

0

This is my radio button code.

<s:radio name="filter" requiredposition="right"
list="#{'STATUS_FILTER_START':'START','STATUS_FILTER_END':'STOP'}" 
 value = "STATUS_FILTER_START"></s:radio>

or

<s:radio name="filter" requiredposition="right"
list="#{'STATUS_FILTER_START':'START','STATUS_FILTER_END':'STOP'}" 
 listValue = "STATUS_FILTER_START" listKey =  "STATUS_FILTER_START"s></s:radio>

But nothing works.
Can somebody help me with this? I dont want html:radio tag.

2012-04-04 05:15
by NIVESH SENGAR
just set the value in your action class and use that value in value parameter.http://stackoverflow.com/questions/1110558/preselect-radio-button-in-struts - Umesh Awasthi 2012-04-04 05:44
@UmeshAwasthi Hi Umesh its not working, I have initialize filter to "START" but still it is not preselecte - NIVESH SENGAR 2012-04-04 06:01
Please see my answer - Umesh Awasthi 2012-04-04 06:13


2

Set default value in your action class and use that in the OGNL to tell which value to select as default

List<String> filter= new ArrayList<String>();
        filter.add("START");
        filter.add("STOP");


    public List<String> getFilter() {
        return filter;
    }
    public String getDefaultFilterValue(){
        return "STOP";
    }

in your jsp use like

<s:radio label="filter" name="filter" list="filter" value="defaultGenderValue" />

i have used simple ArrayList but you are free to use Map.

2012-04-04 06:12
by Umesh Awasthi
Thanks umesh u always help me: - NIVESH SENGAR 2012-04-04 09:05


3

Also for devs who are using static values. Here's the solution:

<s:radio label="correctOption" name="correctAnswer" list=" 
#{'1':'1','2':'2','3':'3','4':'4'}" value="1"/>

another one in case of strings in a static list:

<s:radio label="Gender" name="gender" list=" 
    #{'male':'Male','female':'Female'}" value="'male'"/>
2014-03-24 13:37
by Muhammad Bilal Hasan
Ads