I have researched enough on this topic sans any luck 🙁
My requirement is to load a HashMap that is declared in the action class from the jsp form that has a s:select tag.
Here is my action class
public class AttributeAction extends ActionSupport {
private HashMap<String, String> lstAttrTypesHashMap;
public void setLstAttrTypesHashMap(HashMap<String, String> lstAttrTypesHashMap) {
this.lstAttrTypesHashMap = lstAttrTypesHashMap;
}
public HashMap<String, String> getLstAttrTypesHashMap() {
return lstAttrTypesHashMap;
}
public String renderPageAction() {
lstAttrTypesHashMap.put("ENTRY1", "VALUE1");
lstAttrTypesHashMap.put("ENTRY2", "VALUE2");
lstAttrTypesHashMap.put("ENTRY3", "VALUE3");
return SUCCESS;
}
public String searchAction() {
logger.info("***************************************");
logger.info("searchAction Started ...");
logger.info("a.getType() = [" + a.getType() + "]");
logger.info("getLstAttrTypesHashMap() = [" + getLstAttrTypesHashMap() + "]");
return SUCCESS;
}
}
here is how I show the drop down in the jsp
<s:select
key="a.type"
label="Select Object Type"
name="a.type"
list="lstAttrTypesHashMap" />
Here is the struts.xml
<action name="attributeSearch" method="searchAction" class="com.frk.gid.action.AttributeAction">
<result name="success">/AttributeResult.jsp</result>
<result name="input">/AttributeInput.jsp</result>
</action>
<action name="attributeRender" method="renderPageAction" class="com.frk.gid.action.AttributeAction">
<result name="success">/AttributeInput.jsp</result>
</action>
When the above jsp loads, I can see that the drop down is populated fine. However when I submit it back to the action, i can only see the selected value (a.type) . The hashmap happens to be null. Is there anything else I need to do to get this HashMap loaded? My understanding was Struts2 would automatically load the HashMap from the dropdown on submit – apparently not … appreciate any input !!!!
Thanks very much for your responses !
Finally I decided to go with passing Hidden variables and it worked like a charm.
Also, I had complex types like Map>, I had to write my own Type Converter to convert from and to String.