• 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

c:if doubt

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

In the below code the string "sri" in bold should be given in single quote or double quote. HFSJ book says it can be either single or double quotes. But I get an error when I use double quotes.

<c:if test="${person.name eq "sri"}" var="cond" scope="request">
Welcome!! ${cond }
</c:if>

Thanks
Srividhya
 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you let us know what error it shows?
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EL does allow either single or double quotes... but there's a catch!

If you put EL in an evaluated taglib's attribute, you can't use the same kind of quotes that the tag's attribute uses.

Either of the below would work:
<c:if test='${person.name eq "sri"}' var="cond" scope="request">
Welcome!! ${cond }
</c:if>

<c:if test="${person.name eq 'sri'}" var="cond" scope="request">
Welcome!! ${cond }
</c:if>

Can you figure out why?
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Can you figure out why?



I think in the above codes you used either the doubles quotes or single quotes only one but not both..

But i don't understand why it would work like this?

Can any body tell me on which page in HFSJ 1.4 it is explained..

Thanks & Regards,
Sudhakar Karnati
 
Srividhya Kiran
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its given in HFSJ 1st edition pg no 441.

And I am getting this error org.apache.jasper.JasperException: /result.jsp(18,33) equal symbol expected

and when i place my cursor on the string "sri" it says undefined attribute name sri.

I cant figure out why it didnt work

Srividhya
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srividhya Kiran:
and when i place my cursor on the string "sri" it says undefined attribute name sri.


That's perfect! It explains exactly what is going on.

Let's examine what's happening...
The compiler tries gathering up all the attributes of the rendered tag...
Oh looky! A test attribute!
<c:if test="${person.name eq "sri"}" var="cond" scope="request">

Let's look at what the value for test is. Hmm... I see it starts with a double quote.
<c:if test="${person.name eq "sri"}" var="cond" scope="request">

So now I can assume that the end of the attribute will also be a double quote!
<c:if test="${person.name eq "sri"}" var="cond" scope="request">

Mmmmm.... yummy test attribute!

What attribute do we have next? sri? c:if isn't supposed to have a sri attribute! And the developer didn't even give it an equals sign! What kind of cruel joke is this!
<c:if test="${person.name eq "sri"}" var="cond" scope="request">

*Puke!*
[ July 25, 2008: Message edited by: Marc Peabody ]
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its like this

<c:if test="${person.name eq "sri"}" var="cond" scope="request">

either use like this

<c:if test='${person.name eq 'sri'}' var="cond" scope="request">

or
<c:if test="${person.name eq "sri"}" var="cond" scope="request">

not like this

<c:if test="${person.name eq 'sri'}" var="cond" scope="request">

Please note the changes that i have made to the above inverted commas.
 
Srividhya Kiran
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks marc for your detailed explanation.
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Amandeep Singh:
either use like this...


Umm... your examples have it backwards. See my explanations above.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Marc Peabody
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I searched on the forum before posting a new topic, and I found this . Better to continue this zombie post than posting new stuff right ? Hope that's correct... however...

how should I test two String variables are the same , just like the Java "equals()" method ? Is this correct ?



thanks in advance for any reply!
 
Greenhorn
Posts: 15
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Renato Bobbio Calogero wrote:
how should I test two String variables are the same , just like the Java "equals()" method ? Is this correct ?



Yes, you can test using either "eq" or "==" operators. However, this comparison is case-sensitive as it works just like "equlas()" method in Java. If you want to test the equality by ignoring the case, there isn't any operator for this. First you will have to convert them either to uppercase or lowercase (using JSTL) and then compare. More on string manipulation functions

 
Renato Bobbio Calogero
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for your quick and clarifying answer!

I also had doubt on the toUpperCase() matter, which you solved
 
I am displeased. You are no longer allowed to read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic