passing javascript variable to html tag hidden field

Posted on 2004-11-01
Medium Priority
Last Modified: 2012-05-05
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

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.

Question by:Karls
  • 2

Expert Comment

ID: 12470548
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.

Accepted Solution

Leviter earned 500 total points
ID: 12470566
... 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() %>"/>

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question