• 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:set problem

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
In the following code, <c:out value = "${authorname2}" /> line is not printing the value of authorname2. I want to check if authorname2 has a value or not. I tried alert("authorname2 is: " + authorname2); also. It didnot work. I am not sure if c:set is assigning the value correctly or no. If not, how it can be fixed. Can anyone please help me?
Thank you.

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Suman Sharma:
I tried alert("authorname2 is: " + authorname2);


How would JavaScript know anything about the JSP scoped variable?

Are you sure that your references to the authorsbean properties are correct? They look suspiciously non-bean-like. You should be using standard bean notation.
[ October 18, 2008: Message edited by: Bear Bibeault ]
 
Suman Sharma
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed the name authorbean to authorbean2. I was using the same variable name twice that I used at some other place in this page. So c:set is working fine now.
But it is now completely ignoring the line <c:if test = "${chosen2 == $authorname2}" >
It is supposed to populate the second box with the names of books written by a particular author that is selected in the first box. But the second box is showing all the books regardless of which author name is selected in the first box. It looks like something is wrong in c:if line. Can you please help me?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are mixing client-side JavaScript and server-side JSTL and expecting it to work. It can't. All of the JSP, including the JSTL tags are evaluated on the server long before the page is even sent to the browser for the JavaScript to execute.. So how could they possibly interact?

Please read this article to understand the life-cycle of JSP pages.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Suman Sharma:
I changed the name authorbean to authorbean2. I was using the same variable name twice that I used at some other place in this page. So c:set is working fine now.
But it is now completely ignoring the line <c:if test = "${chosen2 == $authorname2}" >
It is supposed to populate the second box with the names of books written by a particular author that is selected in the first box. But the second box is showing all the books regardless of which author name is selected in the first box. It looks like something is wrong in c:if line. Can you please help me?



<c:if test = "${chosen2 == $authorname2}" > this test is done server-side where chosen2 is no attribute in the application.
But you can solve the problem:
var js_authorname2='${authorname2}';
and make the test in javascript:
if (chosen2 == js_authorname2) {

// anything you want to do in javascript;
// you can surely use any JSTL expressions

}

P.S.
<c:out value="${authorname2}" /> : this is not good at this place it will break your javascript code
--> instead of it you can write: alert('${authorname2});


<c:if test = "${chosen2 == $authorname2}" >
this has wrong syntax
--> <c:if test = "${chosen2 == authorname2}" >
if ever used: chosen2 and authorname2 must both be attibutes in any scope: page, request, session or application
But like i said this is not the right way --> use javascript instead.
[ October 19, 2008: Message edited by: Salah Lejmi ]
 
Suman Sharma
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is working fine. Thanks so much for your help.
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic