• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts2: Compare request parameter not working

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to compare a request parameter with a string and it is not working. Here is what I have done so far:

The request parameter is isServer=false.
In the JSP, I have and it is not working.

Any idea what I am missing?">
 
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
Is this a typo? If not, not enough info to help yet.
 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What info do you need?
 
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
Well, I need to know if it's a typo.
 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is correct, and that is how I am using the s:if tag in my JSP.
 
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
Okay, well, fix the typo first, and see if it works then.
 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ohh if you meant the quotes, then this is what I am using, and it doesn't work:



Sorry, I didn't notice that earlier. If there is any other typo you are refering to then please let me know.
 
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
In your actual code is there anything *in* the tag body?
 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I am trying to print some test text for output to see if it actuall works.

Eg:


Strange thing is that I am using %{#parameters} object in other JSP and it works. Still puzzled.
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using single quotes around false??
 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because double quotes will not work. If I remove quotes, that doesn't work either.
 
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
AFAIK the result of getting a parameter like that will be an array, since a parameter can have multiple values.

As the developer, you have the power to check stuff like this yourself:The more important question is why you'd want to do this, since there's a built-in mechanism to make things like this much, much cleaner, and allow you to use the parameter as a real boolean.
 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry David, I've been travelling over the weekend. If I try to output the class the output is class [Ljava.lang.String;

I did not understand when you mentioned that I can use parameter as real boolean. What did you meant by that? Did you mean that I should have a getter and setter for the request parameter in the Action class?
 
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
So if you wanted to do a string compare, what would you need to do?

Ultimately, yes, I don't see any good reason to be comparing a request parameter directly in the JSP, and for something that's boolean, even less reason to be doing it as a String since the request will have already passed through the normal S2 interceptors, which will do the type conversion for you.
 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the pointer David. I eventually added a getter in my action class which is as shown below:


in JSP I do the following:

The false block never gets executed even when the request parameter is false. Not sure what I missed. Any idea?

This does look much cleaner.
 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem. Figured that out. I now have a getter and setter in the action class, with a boolean property which has the same name as the parameter I was using. Now I dont have to do and getParameterAsString.

This is good.
 
reply
    Bookmark Topic Watch Topic
  • New Topic