File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes c:set problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "c:set problem" Watch "c:set problem" New topic
Author

c:set problem

Suman Sharma
Ranch Hand

Joined: May 16, 2005
Posts: 72
Hello,
In the following code, <cut 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.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Suman Sharma
Ranch Hand

Joined: May 16, 2005
Posts: 72
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

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.
Salah Lejmi
Greenhorn

Joined: Jul 25, 2008
Posts: 22
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.
<cut 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 ]

SCJP 5.0 (95%), SCWCD 5.0 (98%)<br />Salah Lejmi
Suman Sharma
Ranch Hand

Joined: May 16, 2005
Posts: 72
It is working fine. Thanks so much for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: c:set problem