Link to home
Start Free TrialLog in
Avatar of Karls
Karls

asked on

passing javascript variable to html tag hidden field

Hi
I am trying to pass a javascript variable of type long to and struts HTML tag hidden object using the following JSP page code.

<%
long someNumberVariable = 1234567;
%>
<html:hidden property="newSomeNumberVariableObject" value ="<%=someNumberVariable%>"/>

if someNumberVariable is of type String then it works ok.  if it is of type long then I get the following error

cannot resolve symbol
symbol  : method setValue (long)
location: class org.apache.struts.taglib.html.HiddenTag
          _jspx_th_html_hidden_2.setValue(someNumberVariable);

I would prefer to pass the variable in as a long type rather than a String as it saves me doing casting in some class files.

Thanks
Avatar of Leviter
Leviter
Flag of Netherlands image

There is no method in struts to directly write a numeric value into a field (hidden or not).

What you could do is this:

<html:hidden property="newSomeNumberVariableObject" value ="<%= someNumberVariable.toString() %>"/>

That way you don't have to change any classes... only the jsp has to be modified. In HTML there are only string values... that is probably the reason why there is no setter for a numeric value.  :-)

Hope this helps.
ASKER CERTIFIED SOLUTION
Avatar of Leviter
Leviter
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial