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
Reply locked New topic

Problem with html:select

Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
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.

(If this belongs to the JSP forums, then please let me know so that I can move it there.)

Thanks in advance

Thanks ... Raghu
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
It's usually OK to use a scriptlet in an attribute of a Struts tag, but the policy is "all or nothing". By this, I mean that either the entire attribute must be represented by a scriptlet, or else no part of it can be a scriptlet. So, for example, the following would work:

If your Web application is a Servlet version 2.4 application, Struts does support EL expressions as part of an attribute, so the following would work:

In this case, though, "value" must be a scoped variable(page, request, session, etc.), and not just a Java variable.

Consultant, Sima Solutions
Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
Thanks for the help
I used the first method and was able to get the function call.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63867

Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Problem with html:select
It's not a secret anymore!