passing javascript variable to html tag hidden field

Posted on 2004-11-01
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
    LVL 6

    Expert Comment

    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.
    LVL 6

    Accepted Solution

    ... 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() %>"/>

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    In my daily work (mainly using, 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 …
    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    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…

    931 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now