We are using Struts2 in our Java webapplication. There is a Member table(columns name, phoneno.etc.,) which is mapped to Address table(columns street, city, zipcode, country) using a mapped table MemberAddress(old code, no chance of changing the member table to add columns of address in it and remove Address table).
When a user want to edit the member profile, he clicks on settings, which directs him to the execute() method of action class. There am getting the address object with the logged in member id. something like the below code.
protected String execute() throws Exception {
Member loginMember = memberDAO.getLoggedInMember();
memberId = loginMember.getId();
if (StringUtils.isNotBlank(memberId)) {
loginMember = memberDAO.getById(memberId);
Memberaddress memberAddress =
memberAddressDAO.getByMemberId(loginMember.getId());
Address newAddress = null;
if (memberAddress != null && memberAddress.getId() != null) {
newAddress = addressDAO.getById(memberAddress.getId().getAddressid());
} else {
newAddress = new Address();
}
}
return SUCCESS;
}
if the result is Success, it directs to its results page, memberprofile.jsp, which contains input form fields. Here i want to display the existing profile details, including Address object instance variable i.e, street, city, zipcode. How should i get the Member object & Address object in the jsp page. I am trying
<s:set var="address" value="newaddress"/>
and enter its data in the jsp’s input name fields like this.
<input id="addressStreet" type="text"
value="<s:property value="#address.addressstreet" escape="false"/>"/>
but I am getting value=”” in firebug. I thing am doing something wrong while retrieving the output.
Well Struts2 will make your life easy and it will take care of transferring your object from action to the ValuStack and all you need to play around with
OGNLto get values from the Value-stack.I believe you want to place the data in the
newAddressobject and want to retrieve its value in the respectedJSP.All you need to define the property in your action class with getters and setters and let S2 fill the object and transfer it to your the valuestack.
All you need to access the property of the
newAddressobject in the ValueStack using OGNL likeWhen the success result will send back from your action class S2 will place
newAddresson the top of Value Stack and we have OGNL to access them.