I am using Struts 2.0. I have a Java Bean Person having fields perName, perAge, perMail & many more. I want to display a Map of Java Bean {[1, person1], [2, person2]) on JSP and allow the user to update it from the same JSP using text fields. There are lot of variables in the bean and some of them are editable while some of them are not.
For example, perName is not editable while perAge is editable. I don’t want to display non editable fields. If I use ediatable fileds only, after updating, I get non editable fields as null (perName is null after update). So I can’t specify name attribute as it is changing at run time. So I am putting them in HTTP Session and displaying them. I am specifying name attribute of text field using #session.person[iterator index].perAge. Till this point everything works fine. But if I change the value in any text field & try to update, I get the old session attribute instead of changed one. I want the old session attribute with the new changed values and values of non editable fields should persist within user request. I don’t want to use JavaScript. OGNL or expressions are most welcome.
public class PersonDTO implements Serializable {
private String perName;
private int perAge;
public String getPerName() {
return perName;
}
public void setPerName(String perName) {
this.perName = perName;
}
public int getPerAge() {
return perAge;
}
public void setPerAge(int perAge) {
this.perAge = perAge;
}
}
<s:form action="updatePerson" id="updatePerson">
<table>
<tr>
<td>AGE:<s:textfield name="#session.person.perAge" />
</td>
</tr>
<tr>
<td><s:submit id="update" value="Update" />
</td>
</tr>
</table>
</s:form>
Thanks for your support. After a day long GOOGLE, I found that it is not possible to update session directly using Struts tags. You can use session information for display and update session in scriplets but you can’t update session directly. You may refer Struts2 form to update object in Session map? for more info. Once again thanks for help!!!