• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Conditional alerts (was 'c:otherwise tag')

 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to display an alert window inside c:otherwise.
I tried using script tag to write the function inside it..
It wouldn't work..
How to insert that code between the c:otherwise tags?..






[BPSouther: changed subject line before moving to HTML/Javascript]
[ June 28, 2007: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Bear Bibeault
Sheriff
Posts: 67637
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
If you are expecting to mix server-side Java and client-side JavaScript, perhaps you should read this article.
 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to mix jsp and javascript rather..
<c:otherwise>
<script type="text/javascript">
function q()
{
alert("error");
}
</script>
</c:otherwise>

Please help me to display the alert message..
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you trying to use the c:otherwise 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
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 c:otherwise tag..



[BPSouther: Added code tags]
[ June 27, 2007: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do see the javascript function..
But it still doesn't bring me the error alert..
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you see the javascript function then your c:otherwise 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 c:otherwise 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
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried what you've suggested..
When I add resultsEmpty=false line into c:choose and c:otherwise, it just prints it..
It never sets the value..
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you know it's not setting the value?
 
Amit M Tank
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
remove the funtion. Have only the alert(). It will work.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic