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
KarlsAsked:
Who is Participating?
 
LeviterConnect With a Mentor Commented:
... and now I see that it is of type 'long' and not of type 'Long'. This is a big difference, since the 'long' has no method 'toString' since it is a base type. What the line should be is:

<html:hidden property="newSomeNumberVariableObject" value ="<%= Long(someNumberVariable).toString() %>"/>
0
 
LeviterCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.