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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Reply locked 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.

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

Thanks in advance
RS


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.


Merrill
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.

RS
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with html:select
 
Similar Threads
Problem with html:select
select tag in struts
implementing dependent select boxes in struts1.2.9 and netbeans6.5
how to populate dependent <html:select >
using c:out in a href and html:select