NIVESH SENGAR NIVESH SENGAR -4 years ago 83
HTML Question

Pre select a <s:radio> button in struts 2

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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download