how to compare list elements(type string) and string(in request scope) using struts 2 tags

With the IteratorStatus object: <s:iterator value=”lis” status=”ctr”> <s:property /> <s:if test=”%{#request.str.equals(lis[#ctr.index])}”> -> This value from “lis” is equal to the value of “str” </s:if> <br/> </s:iterator> With the var parameter: <s:iterator value=”lis” var=”currentValue”> <s:property /> <s:if test=”%{#request.str.equals(#currentValue)}”> -> This value from “lis” is equal to the value of “str” </s:if> <br/> </s:iterator> With the top … Read more

Make ${} operator XSS safe in Struts 2 (same as tapestry)

Struts2 <s:property value=”name” /> is automatically escaped by default; JSTL <c:out value=”${name}” /> is automatically escaped by default; JSP EL ${name} is NOT escaped. You can explicitly escape it with ${fn:escapeXml(name)} , or set the escape to be performed by default creating a custom ELResolver as described in this great article: ELResolver Escapes JSP EL … Read more

Struts2 passing variables case

but Struts2 cannot receive this kind of camelcase style (just first one char lower and second upper case) This is actually not true. Struts2 can receive any variable name that comply JavaBeans spec. But apart from the Java implementation of this spec. (if you want to learn more about JavaBeans, see this post What is … Read more

What’s the difference between # , % and $ signs in Struts tags?

Use of # (pound sign) OGNL is used to refer to objects in the ActionContext as follows: objectName: object in the ValueStack (default/root object in the OGNL context), such as an Action property #objectName: object in the ActionContext but outside of the ValueStack, specifically… #objectName: ActionContext object that has been created using the Struts2 data … Read more

Struts2: Updating the values of a “List Of Objects” inside a Map

According to your latest update. If you are using TreeMap Struts2 cannot correctly determine type of elements inside it. Change declaration of testTreeMap from TreeMap to Map. private Map<String,ObjectCList> testTreeMap = new TreeMap<String,ObjectCList>(); Or annotate testTreeMap with com.opensymphony.xwork2.util.Element annotation to tell Struts2 what type are elements inside map. @Element(value = ObjectCList.class) private TreeMap<String,ObjectCList> testTreeMap = … Read more