aspose file tools*
The moose likes JSP and the fly likes EL tag for setting textfield values using Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "EL tag for setting textfield values using Javascript" Watch "EL tag for setting textfield values using Javascript" New topic
Author

EL tag for setting textfield values using Javascript

Abdul Wahab
Ranch Hand

Joined: Dec 09, 2011
Posts: 49

Hi all,
This is my first post. i am confused on How to use EL tag for setting values to my Address Field using getdetails(value) method (i am using javascript here).
Below is my JSP code


here tanneryarray is an arraylist having my tannerydetails(tanneryid, tanneryname, tanneryAddress)
which i collected using Bean Setter method from DB. here is my DAO class
i forwarded this prftanneryDetailslist from servlet to jsp by request.setAttribute. Now i want to set dynamically the value of Address
by selecting Tannery Name. :eek:
Any Help on this will be appreciated.
thanks


As long as breath left in my body there is hope
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Welcome to the Ranch.

It's not clear exactly what your question is. You can use an EL expression (not "tag") anywhere in the template text. JSP doesn't know anything about HTML or JavaScript -- to it, it's all just a text blob. So it doesn't matter if you are using EL expressions in HTML, or JavaScript, tr any other template text on the page. The value of the EL will simply be substituted in place.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Abdul Wahab
Ranch Hand

Joined: Dec 09, 2011
Posts: 49

hi,
Sorry for using Tag. My Question is By Selecting Tannery Name in the Select tag. I am passing the corresponding Tannery Id
to the Javascript Function getDetails. Is there any possibility, by using arraylist tanneryarray, to get the corresponding Tanneryaddress
for the selected Tannery Name.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Well, no. Remember that JSP operates on the server in order to format an HTML page to send to the browser. Once the response is sent, there can be no more JSP actions as the page is just an HTML page at that point. JavaScript is evaluated on the browser after the response has been sent.

If this is not clear to you, I suggest reading this article.

If you need for your JavaScript to interact with data, what you can do is to use JSP/EL/JSTL to generate JavaScript code that creates these constructs in JavaScript on the client; which your JavaScript code can then access and interact with.
Abdul Wahab
Ranch Hand

Joined: Dec 09, 2011
Posts: 49

Thank you very much Bibeault,
It Will be very useful if you give me a code example for below quote..
Bear Bibeault wrote:

If you need for your JavaScript to interact with data, what you can do is to use JSP/EL/JSTL to generate JavaScript code that creates these constructs in JavaScript on the client; which your JavaScript code can then access and interact with.
.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

OK, let's say that you had a scoped variable named whatever that is a String with a value of "Hi there!" that you needed to access in JavaScript. As has already been pointed out, you can't access that Java value once the response is sent to the browser, so you need to create a JavaScript equivalent:

This results in the following being sent to the browser:

With more complex constructs, such as an array or List, you'd use a combination of the JSTL and EL to create a corresponding JavaScript array. For example you'd need to figure out how to use JSTL and EL on a List to end up with markup similar to the following:

I will not write that code for you; you'll need to take a stab at it and post back with any issues you are running into.
Abdul Wahab
Ranch Hand

Joined: Dec 09, 2011
Posts: 49

Hi,
I am trying something like this.


Now this myArray should hold the value of all the tannery address. but in my case it holds only the last value.
I guess there is something i miss. any ideas???
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

You're not providing enough info to help. How are the lists being used constructed? What's in them? What's being sent to the browser?
 
Don't get me started about those stupid light bulbs.
 
subject: EL tag for setting textfield values using Javascript