[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

656 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