File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Conditional alerts (was 'c:otherwise tag') Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Conditional alerts (was Watch "Conditional alerts (was New topic
Author

Conditional alerts (was 'c:otherwise tag')

Steve Renard
Ranch Hand

Joined: Apr 27, 2007
Posts: 66
I want to display an alert window inside ctherwise.
I tried using script tag to write the function inside it..
It wouldn't work..
How to insert that code between the ctherwise tags?..






[BPSouther: changed subject line before moving to HTML/Javascript]
[ June 28, 2007: Message edited by: Ben Souther ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Steve Renard:

It wouldn't work..


It's very difficult for folks on a forum to help with something when all they have to go by is "it wouldn't work".

Maybe you can post the relevant parts of your code so we can see what went wrong?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61755
    
  67

If you are expecting to mix server-side Java and client-side JavaScript, perhaps you should read this article.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Renard
Ranch Hand

Joined: Apr 27, 2007
Posts: 66
I want to mix jsp and javascript rather..
<ctherwise>
<script type="text/javascript">
function q()
{
alert("error");
}
</script>
</ctherwise>

Please help me to display the alert message..
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Are you trying to use the ctherwise tag alone?
It's meant to be nested inside a c:choose tag.

If not, please post enough of the code for use to see what you're really doing.
Steve Renard
Ranch Hand

Joined: Apr 27, 2007
Posts: 66
Here's the entire code:
I'm looking to display a message when the search results are empty..
That's why I try to put the alert inside ctherwise tag..



[BPSouther: Added code tags]
[ June 27, 2007: Message edited by: Ben Souther ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you run it with no results in your query and look at the HTML source generated by your JSP, do you see the Javascript function?
Steve Renard
Ranch Hand

Joined: Apr 27, 2007
Posts: 66
I do see the javascript function..
But it still doesn't bring me the error alert..
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you see the javascript function then your ctherwise tag is doing exactly what it's supposed to do.
Merely printing it to the page is not going to cause it to be executed.

Instead of printing a function, why not write the value of a variable that can be read from the document's onload event.



Since you only need one test, you could probably do away with the c:choose and just use a c:if tag that changes the resultsEmpty to true.

Either way, your issue isn't with the ctherwise tag (or JSP for that matter), it's with Javascript.
If you need any more help with Javascript, let me know and I'll move this thread to our HTML/Javascript forum.
[ June 27, 2007: Message edited by: Ben Souther ]
Steve Renard
Ranch Hand

Joined: Apr 27, 2007
Posts: 66
I tried what you've suggested..
When I add resultsEmpty=false line into c:choose and ctherwise, it just prints it..
It never sets the value..
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

How do you know it's not setting the value?
Amit M Tank
Ranch Hand

Joined: Mar 28, 2004
Posts: 257
remove the funtion. Have only the alert(). It will work.


Amit Tank
Linked In
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Amit M Tank:
remove the funtion. Have only the alert(). It will work.



Doing that will stop the drawing of the page until the user clicks the OK button in the alert.
The onload event isn't called until the entire body has been drawn.

This conversation has moved away from JSP a while ago.
I'm going to move it to our HTML/Javascript forum where our Javascript Gurus hang out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Conditional alerts (was 'c:otherwise tag')