Nitish
Nitish

Reputation: 856

How to set the radio button value checked by default in struts2?

The code I am using is:

<table>
  <tr>
    <td>
      <s:radio name="dlrMaintenanceVO.dbsVO.substitutionMethod" id="substitution" label="" list="#{'M':'Moves History'}" /> 

      <br/>
      <s:radio name="dlrMaintenanceVO.dbsVO.substitutionMethod" id="substitution" label="" list="#{'R':'Reports History'}" value="R"/>
    </td>
  </tr>
</table>

This should make radio button with R value as checked by default. But this thing is not happening. Any suggestions.

Upvotes: 3

Views: 12677

Answers (3)

VNN456
VNN456

Reputation: 147

Please change value to value="'R'"

Upvotes: 2

Rex
Rex

Reputation: 77

I'm okay with following code to set default value in radio button in struts 2.Type checked="true" you want to default in radio tag.

<table>
  <tr>
    <td>
      <s:radio name="dlrMaintenanceVO.dbsVO.substitutionMethod" id="substitution" label="" list="#{'M':'Moves History'}" checked="true"/> 

      <br/>
      <s:radio name="dlrMaintenanceVO.dbsVO.substitutionMethod" id="substitution" label="" list="#{'R':'Reports History'}" value="R"/>
    </td>
  </tr>
</table>

Upvotes: 1

Umesh Awasthi
Umesh Awasthi

Reputation: 23587

Make sure that R should have correct value set in your action class.All you need to set the required value in your action class for R and based on the value it will select the appropriate radio button

Upvotes: 0

Related Questions