I have a screen where i want the components disabled when i first traverse to the screen(view mode). When i click on Edit button an action is fired and i reload the same screen with the components (cName and cStatus) as editable. Previously, i couldn’t retain the values of cID, cName and cStatus when the screen was reloaded so i made 3 hidden fields with the same names. Now i am able to retain the values of all the 3 pages in editable mode(modify mode).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
</head>
<body>
<s:form name="c" validate="true">
<s:hidden name="cID" />
<s:hidden name="cName" />
<s:hidden name="cStatus" />
<table cellspacing="0" cellpadding="3">
<tr>
<s:if test="%{mode=='view'}">
<td><s:submit name="btnEdit" value="Edit" onclick="onEdit()" /></td>
</s:if>
<s:elseif test="%{mode=='modify'}">
<td><s:submit name="btnSave" value="Save" onclick="onSave()" /></td>
</s:elseif>
<td><s:submit name="btnBack" value="Back" onclick="onBack()" /></td>
</tr>
</table>
<fieldset style="width: 60%"><legend>Details</legend>
<table cellspacing="0" cellpadding="5" width="100%">
<tr>
<td><s:label name="ID" value="ID" /></td>
<td><s:label name="cID" /></td>
</tr>
<tr>
<td><s:label name="Name" value=" Name" /></td>
<s:if test="%{mode=='view'}">
<td><s:textfield name="cName" disabled="true" /></td>
</s:if>
<s:elseif test="%{mode=='modify'}">
<td><s:textfield name="cName" id="id2" /></td>
</s:elseif>
</tr>
<tr>
<td><s:label name="CStatus" value="Status" /></td>
<s:if test="%{mode=='view'}">
<td><s:select name="cStatus"
list="#{'Y':'Active', 'N':'Inactive'}" disabled="true" /></td>
</s:if>
<s:elseif test="%{mode=='modify'}">
<td><s:select name="cStatus"
list="#{'Y':'Active','N':'Inactive'}" /></td>
</s:elseif>
</tr>
</table>
</fieldset>
</s:form>
</body>
</html>
Now my problem is that,
suppose if i have value “xyz” in cName and “Single” in cStatus.
In modify mode i change the values to “xyza” in cName and “Married” in cStatus and submit the form.
In action class i receive the Value Object set as
cName=”xyz, xyza”
cStatus=”Single, Married”
instead of
cName=”xyza”
cStatus=”Married”
To resolve this problem i added
statement to jsp i.e. i am using hidden tag only in view mode. Now in modify mode as both textfield and select tags are enabled, Value Object is automatically set, so there is no need to pass hidden values. Its working now.