I am new to Struts2 and currently working on Struts1.x to Struts2 migration. I need to change logic:equal and logic:present tags in the Jsp. Here is the problem I am facing:
STConstants.java has some constants such as:
public static final string ALT_PBR = "fusion";
Customer.java is a POJO having the following fields with getters and setters:
In NewCmpAction.java we have:
Customer cust = new Customer();
//code which sets all the fields in cust object
//cust object is placed in session
In slsDetail.jsp, I want to check if "cust" objects exists in session, if it exists then if the value of city field in "cust" object is equal to "CA".
In Struts 1.x we used logic:equal and logic:present but in Struts2 we do not have logic:equal and logic:present and I assume we have to implement this logic using if tag. I tried various combination but it didnt work.
I know if I use #session.fusion.city I will get the city value which I can compare to "CA" but I want to get the value "fusion" by referring to STConstants.ALT_PBR in the jsp. How can I do that? For eg: #session.???.city where ??? = STConstants.ALT_PBR.
Also, how can I check if session has "cust" object? or how can I check if it is not present in session.
David Newton wrote:Try #session[@static.pkg.and.class@CONSTANT_NAME]
Just check if it's null or not.
I tried to first print the constant value in the Jsp to see if its working using s:property but it didnt work.
com.hcl.st is tha package name
STConstants is class name
ALT_PBR is constant name
<s:if test="#session[@com.hcl.st.and.STConstants@ALT_PBR].city.equals('CA')> ---> This works perfect! Thank you for your help on this.
However I am not able to check if the cust object exists in session.
<s:if test="#session[@com.hcl.st.and.STConstants@ALT_PBR] == null"> ---> This didnt work
<s:if test="#session[@com.hcl.st.and.STConstants@ALT_PBR] !=null"> ---> This didnt work
Both of them didnt work
How can I check if an object is present in a session? Please help!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Help on Struts2 if tag to implement logic:equal and logic:present