This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Calling javascript function from scriptlet Xpost Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Calling javascript function from scriptlet Xpost" Watch "Calling javascript function from scriptlet Xpost" New topic
Author

Calling javascript function from scriptlet Xpost

Mike Anna
Ranch Hand

Joined: Jul 08, 2007
Posts: 117
Hello,

I need to call a Javascript function from within my scriptlet.
Now I am pretty aware that I cant do that. Let me tell you what I want to do: To display a message next to the item being displayed(now there is a list of items and their attributes in one page), based on the value of one of the parameters, that belong to that item. The query that fetches the item and its attributes happens in the JSP (thats not my fault, I am just enhancing something already existing)
So what I tried to do was wrote a function (which updates the innerHtml of a DIV tag, which is placed next to the line where the item is displayed)
and did an

Now, the warning is displayed somewhere on the top of the page (not where I expect it to be) and the page stops rendering after encountering the iframe
however now, when i look at the source code, the rest of the items and attributes are there, but probably hidden behind the iframe. I am not able to resize this iframe either. I used iframe because that is one tag which offered me an onload functionality.

So basically, I am kind of stuck and was wondering if some one could show me a way.

many thanks,
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

Sorry, still not sure what you are trying to accomplish, but I'm pretty sure an iframe isn't the answer.

Please explain a bit more clearly what you are hoping to accomplish.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike Anna
Ranch Hand

Joined: Jul 08, 2007
Posts: 117
Thanks for the answer.
Ill try and explain. For example, let us assume, there is a page which takes in a bill number and then the page redirects to another JSP with the bill number. In the next JSP there are some queries that run with the bill number, which return the details of the bill number. Assume we get a collection(vector etc) returned. Now that vector is looped through and the details of the bill ( which include an order no. and its attributes) displayed. Now from the details, if one of the attributes of an order is 'XYZ' then, where the order no. is displayed, I need to display a message.
For this, as explained above, I put a div tag next to the order no. being displayed
and then I wrote a javascript :


and in the place where I am iterating, I did this :

which I think is obviously wrong.

I hope I explained it clearly this time.

thanks for your time on this.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

Nope. You still have not explained why you think JavaScript is even necessary. What's its purpose? Stop trying to write code and explain what you are really trying to accomplish.
Mike Anna
Ranch Hand

Joined: Jul 08, 2007
Posts: 117
oops... I am sorry for the reposts. EDIT: Ok, I deleted them
I clicked add reply and the page always timed out.

Ok, the javascript is necesary because I think that is the only way I can update the Div tag's contents, which will display the warning message, after the attribute has been read and valued to be equal to "XYZ". There is no way I can know the value is "XYZ" before I iterate through the collection.
[ November 29, 2008: Message edited by: Mike Anna ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

Unless I'm missing something major, why cannot you just set it in JSP on the server? What decision needs to wait until the page is sent to the browser?
Mike Anna
Ranch Hand

Joined: Jul 08, 2007
Posts: 117
Thanks for your answer.
>What decision needs to wait until the page is sent to the browser?

There is no way I can set it on the server side.
The queries are executed in a JSP and the display also happens in the same page. Therefore, I need to be able to do this while the collections are being iterated in the JSP.
Any help appreciated.


thanks
Mike Anna
Ranch Hand

Joined: Jul 08, 2007
Posts: 117
Done !
All I had to do was, use less of brains and more of basics. This is what solved my dilema of having to call a js function from a scriptlet based on a condition :
First styled my div as

then this


[ December 02, 2008: Message edited by: Mike Anna ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling javascript function from scriptlet Xpost
 
Similar Threads
problem paging HTML table
IFRAME with POST
Passing data using netui
iFrame related topic
JSF with fileupload and iframe