We need to display only 1 of the labels depending on condition. This is done through Javascript. That works fine, but the issue is we get a 508 compliant error saying 1 form element has 2 labels. The issue is with "for" in the table. Removing it also shows a 508 error. I tired to change the second label for to for="org.dateOfReg", but still the same. Is there a way to have only 1 label and pass the "for" and "name" values dynamically from javascript? Or is there any other option? Please help. Appreciate it a lot.
<tr id="showDates">
<td id="TypeDate1"><s:label for="dateOfReg" name="dateofReg" value="Date of Interest" /><span class="required" >*</span> :</td>
<td id="TypeDate2"><s:label for="dateOfReg" name="dateofReg" value="Date of Completion" /><span class="required" >*</span> :</td>
<td id="typeDatePick">
<sj:datepicker showButtonPanel="true" id="dateOfReg" name="org.dateOfReg" displayFormat="mm/dd/yy" label="Date of Interest" changeMonth="true" changeYear="true" size="7"/>
</td>
</tr>
Thanks
Harry
Here is what you can do to resolve this. Just have one label and change its innerHTml using JavaScript instead of hiding the label.
<tr id="showDates">
<td id="TypeDateLabel"><s:label for="dateOfReg" name="dateofReg" value="Date of Interest" /><span class="required" >*</span> :</td>
<td id="typeDatePick">
<sj:datepicker showButtonPanel="true" id="dateOfReg" name="org.dateOfReg" displayFormat="mm/dd/yy" label="Date of Interest" changeMonth="true" changeYear="true" size="7"/>
</td>
</tr>
<script language="javascript">
function TriggerToChangeLabel(triggerCondition)
{
if (triggerCondition)
$("dateOfReg").innerHtml = "Date of Interest";
else
$("dateOfReg").innerHtml = "Date of Completion";
}
</script>
But keep in mind that even though it makes the code 508 compliant; Dynamically changing the label text goes against the spirit of the accessibility. Better way to implement the same is it to have two date fields ("Date of Interest" and "Date of Completion"). Upon submission enforce "required" edit on one of the field based on the condition you have for the label change.
Related
I am iterating a list object in jsp file which is coming from action class.
Using table,tr,td tags in order to dispay value in tabular format as follows.
<s:iterator value="userList" >
<tr>
<td><s:property value="name" /> </td>
<td><s:property value="gender" /> </td>
<td><s:select name="country" list="countryList" value="%{country}" /> </td>
<td><s:property value="aboutYou"/> </td>
<td><s:property value="malingList /> </td>
<tr>
</s:iterator>
I need to display country drop down with selected value. Which is displaying but not in a proper format. Name and gender is showing in first line, country drop down showing in second line and aboutYou and mailing list showing in third line.
I tried to display drop down value inside tag but not displaying.
What i need to display is all five fields in one single line(tr)
Requesting you please help me.
Thanks in advance.
I need to be able to use the same drop down list multiple times on a page. The first time i use the 'list' on the select tag, it works fine. The same list does not populate the second select tag i use it on. Here are the details.
In the action class, i populate the ArrayList containing values i need to populate the select tag.
setNames(new SomeDAO().getNames());
In the JSP
<s:select list="names"
id="nameList"
listKey="nameId"
listValue="userName"
/>
This select list populates just fine. If I use the following select tag on the same page (using the same list), it fails to print.
<s:select list="names"
id="rName"
listKey="nameId"
listValue="userName" />
If i replace the 'list' above with #{'test':'test'} (hardcoded list), the tag shows up fine. Looks like the property i set in the Action is getting cleared after the first use. Is that whats happening or am i doing something wrong? I get an 'IllegalStateException: Response already committed' error
Edit 1:
setNames() is used in the action method that deals with the JSP page. It is a simple getter function.
In the JSP, here is what i have.
<tr>
<td align="left" class="td-plain">Add New:</td>
<td class="td-plain">
<s:select list="names"
id="addNameID"
name="addUserNameID"
listKey="reinsId"
listValue="reinsName"
headerKey=""
headerValue="--User Name--"
/>
</td>
<td class="td-plain"><input id="addTreatyNumber" type="text" /></td>
<td class="td-plain"><input id="addReinsPercentage" type="text" /></td>
<td class="td-plain"><input id="addFlatDollarRetentionAmt" type="text" /></td>
<td class="td-plain">
<%if(finance){ %>
<input type="button" class="greyButton" value="Add" onclick="addReinsInfo()"/>
<%}else{ %>
None
<%} %>
</td>
</tr>
and then later down on that page, i have
<tr id='<s:property value="caseGroupId"/>:<s:property value="treatyId"/>'>
<td class="td-plain"><input type='checkbox' id='<s:property value="caseGroupId"/>:<s:property value="treatyId"/>'/></td>
<td class="td-plain">
<s:select list="names"
id="rName"
name="dName"
listKey="reinsId"
listValue="reinsName"
headerKey=""
headerValue="--User Name--"
/>
</td>
<td class="td-plain_"><s:textfield id="tNumber" value="%{treatyNumber}"/></td>
<td class="td-plain_"><s:textfield id="tPercentage" value="%{reinspercentage}"/></td>
<td class="td-plain_"><s:textfield id="rAmount" value="%{flatDollarRetentionAmt}"/></td>
<td class="td-plain"><input type="button" value="Delete" class="greyButton"/></td>
</tr>
If I change the 'list' in the second tag to
list="#{'Test':'Test'}"
the tag shows up fine. Please let me know if i can provide any further info.
Edit 2: I was able to get this to work by setting the drop down list values to the session.
As asked by #Dave and #Quaternion, post the relevant Java/JSP code.
But until then... I've noted that you are not using name attribute in Struts Selects;
while you can refer multiple times from different tags to the same source (the list attribute), to populate the Select from the same list of objects, you should instead specify a different name for each one, to define which variable (sent back to the Action) contains the selected value of which Select;
this may not be the answer to the current question but it will show up to you soon.
The following jsp file fragment using struts2 tags doesn't show the textfield label. How can I fix this? Is it possible to have the label displayed by using only struts2 tags?
<s:form action="voucher" theme="simple">
<table width=50% border="5">
<tr>
<td>
<s:textfield label="Enter the voucher hrn" name="voucher.SN" />
</td>
<td>
<s:submit value="Check state" />
</td>
</tr>
<tr>
<td>
<s:radio list="#{'used': 'Mark as used', 'available': 'Mark as available'}" name="selections" value="%{'used'}"></s:radio>
</td>
<td>
<s:submit value="Update state" />
</td>
</tr>
</table>
</s:form>
It is because you are using simple theme in your form. Remove theme="simple" from <s:form> tag then Struts2 will do table layout as well field errors and labels for you.
BTW if you really need to use your custom layout then use <s:label> tags for labels.
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.
Please change value to value="'R'"
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>
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
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_SelectedValue == '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.