开发者

Iterator, set, if-else tags of Struts2(Getting the value of s:radio and applying if-else )

开发者 https://www.devze.com 2023-04-01 06:32 出处:网络
I have a jsp page in which I have two radio buttons and a select tag. Now, if the first radio button is clicked than I want to make that select tag disable but I am fail to do this , I have tried usin

I have a jsp page in which I have two radio buttons and a select tag. Now, if the first radio button is clicked than I want to make that select tag disable but I am fail to do this , I have tried using "disabled" property. Following is the code. Jsp Page

<table align="center">
<s:iterator value="FirstObjectList" status="AuthorTypeStatus">
    <tr>
        <td>
            <s:radio name="radio_SelectedValue" list="{ObjectName}" listKey="ObjectKey" listValue="ObjectName" value="DefaultObject"/>                                  
        </td>
    </tr>           
</s:iterator>
<s:if test="%{#radio_SelectedV开发者_如何转开发alue == 'ObjectName1'}">
    <s:set name="isSelectDisabled" value="false"/>              
</s:if>
<s:else>
    <s:set name="isSelectDisabled" value="True"/>
</s:else>

<tr >
    <td colspan="2">
        Select Parent Discover Lab
    </td>           
</tr>       
<tr>        
    <td>
        <s:select name="select_SelectedValue" headerKey="DefaultObject" headerValue="ParentObject" list="ObjectList" listKey="ObjectListKey" listValue="ObjectListValue" disabled="%{isSelectDiabled}">
            <s:iterator value="ObjectList">
            </s:iterator>
        </s:select>

        <s:submit value="Continue">
        </s:submit>                         
    </td>

</tr>       

All the getter and setter methods are fixed..is this possible without javascript?


I'm a little confused by your code block, but I think I understand what you're aiming for. Something like this should work

    <tr>
        <td>
            <s:radio name="radio_SelectedValue" list="%{radioList}" listKey="ObjectKey" listValue="ObjectName" value="DefaultObject"/>                                  
        </td>
    </tr>

    <s:if test="%{radio_SelectedValue.equals('myChosenValueFromTheList')}">
             <s:select name="select_SelectedValue" headerKey="-1" headerValue=" " list="ObjectList" listKey="ObjectList.Key" listValue="ObjectList.Value" />       
    </s:if><s:else>
        <s:select name="select_SelectedValue" headerKey="-1" headerValue=" " list="ObjectList" listKey="ObjectList.Key" listValue="ObjectList.Value" disabled="disabled" />   
    </s:else>       

I'm not sure what you're doing with the iterators with these tags, they handle the list propagation themselves. Simply tell the tag what list to use and struts will populate the tags appropriately. You can then do a conditional based on the value of the radio when the page renders and perform magic on the select tag as shown above.

0

精彩评论

暂无评论...
验证码 换一张
取 消