aspose file tools*
The moose likes Struts and the fly likes Problem with html:select Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with html:select" Watch "Problem with html:select" New topic
Author

Problem with html:select

Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
Greetings,
I'm having a problem with setting server side values as a parameter to a javascript function that I am calling during an "onchange" event of an html:select that I have.
The line in my jsp is something like this:

<html:select name="stList" property="attempt.attainmentLevel" onchange="javascript:trackChanges( <%=value%>);" indexed='true'>

The problem with the above line is that when I view source code after my page is rendered is that the dynamic value is not replaced but I see the <%=value%> as it is!

Now as I was debugging, I replaced this with the regular <select> html tag.

<select name="stList" property="attempt.attainmentLevel" onchange="javascript:trackChanges( <%=value%>);" indexed='true'>

In this case, I am able to see the processed server side value for <%=value%>.

It is important for me to use html:select and if I do that what do I have to do so that I can pass the dynamic server side value to my javascript function?

I hope I have been articulate enough to explain my problem - please let me know if you need further information.

Thanks in advance
RS


Thanks ... Raghu
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

You cannot use a scriptlet expression as just part of an attribute of a custom action. It must compose the entire attribute value.

No such restructions exists with the EL in JSP 2.0.
[ March 30, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
Thanks for the prompt reply ...

I have couple of questions:
- I do pass scriptlet values to custon tag libraries and they are able to read the,. Why should the tag library for tags-html be any different?

-Is there a work around to this one?

Thanks
RS
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Originally posted by Raghu Nathan:

- I do pass scriptlet values to custon tag libraries


Only as the complete attribute:



Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
Thanks for that tip - I created a server side string variable that would call the javascript function. I used this in my onchange event

<%
String funcCall = "javascript:function funA(" + var1 + ");";
%>
onchange=<%=funcCall%>

Just gave a sample so that others could benefit if they come across a similar problem.

Thanks again, your tip helped me.
RS
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Glad to have helped. I would urge you to begin thinking about adopting JSP 2.0 and removing scriptlets and scriplet expressions from your JSPs.
ganesh musa
Greenhorn

Joined: Sep 19, 2007
Posts: 2
Thanks Bear Bibeault & Raghu for this post ....
ganesh musa
Greenhorn

Joined: Sep 19, 2007
Posts: 2
Hi Bear Bibeault,
What do you mean by using JSP2.0? how can I get rid of jsp scriptlets in the above condition. I tried using struts <bean:write> & <bean:define> stuff but i endup with same problem...
Pls share if any suggestions. Many Thanks
Ganesh
Java Rider
Greenhorn

Joined: Jul 09, 2009
Posts: 1
or you can do something like the following. Had the same issue and resolved it. Thought of putting it here so that it might help someone.

<select name="stList" property="attempt.attainmentLevel" onchange='<%= "javascript:trackChanges(" + value + ");" %>' indexed='true'>

Thanks.
-S
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

"Java Rider", please check your private messages for an important administrative matter.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with html:select