Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling javascript function from scriptlet Xpost

 
Mike Anna
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Anna
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic