• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Help on Struts2 if tag to implement logic:equal and logic:present

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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:
firstname, lastname,addressline1,addressline2,city,state,postalCode

In NewCmpAction.java we have:
Customer cust = new Customer();
//code which sets all the fields in cust object
.
.
//cust object is placed in session
session.put(STConstants.ALT_PBR,cust);

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.

Please help.
Also, how can I check if session has "cust" object? or how can I check if it is not present in session.


Thanks,
Prathima

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try #session[@static.pkg.and.class@CONSTANT_NAME]

Just check if it's null or not.
 
Prathima Gajibiji
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
#session[@static.com.hcl.st.STConstants@ALT_PBR]
#session[@static.com.hcl.st.and.STConstants@ALT_PBR]
#session[@static.STConstants@ALT_PBR]

com.hcl.st is tha package name
STConstants is class name
ALT_PBR is constant name

None of them worked.

Please help.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...

remove the word "static".

Issues like this are easily solved by looking at the Struts 2 documentation:

http://struts.apache.org/2.1.8/docs/ognl-basics.html
 
Prathima Gajibiji
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David! It worked

<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.
For example:
<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!

Thanks
Prathima G
 
Uh oh, we're definitely being carded. Here, show him this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic