• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

set tag not working for numeric data types

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am using Struts 2.3.x. I have an action class in which there is a private variable "identification_number" of type double with its public setter and getter methods. The getter method returns double.

In the execute() method, I set the value of this variable to 2155.

On my JSP, I want to repeatedly use this variable so I prefer a shorter name "id".

So when I tried to use <s:set var="id" value="identification_number" /> I got the following exception:

Struts Problem Report
Struts has detected an unhandled exception:

Messages: java.lang.Double cannot be cast to java.lang.String

My question is how to use the set tag for numeric data types?

Regards,
John.


 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The documentation for the set tag says it sets a variable to a value. You are setting "identification_number" to a string value.
 
Johnnie Smith
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You Joe.

Yes I want to assign the value of identification_number to a variable id. But identification_number is of the type double in action class.

So I want to know how to assign a numeric value to a variable on the JSP. I had gone through the documentation before posting the question.

The example that is present there is:

<s:set name="personName" value="person.name"/>
Hello, <s:property value="#personName"/>. How are you?

The name of the person is of type String so this will not create any problem. Is there any technique of using the <s:set> tag to assign numeric value to the variable? Or is it necessary that the value we are assigning should strictly be a String value?

Regards,
John
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry. I read the documentation wrong
So the problem isn't the set tag itself (though it is changing the double to a String). Is the problem working with the double in the JSP or submitting the value back to the action?
 
Johnnie Smith
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Joe,

The problem is with the set tag.

The value of identification_number is already set in the execute() method of the action class and it is of the type double.

Because the name identification_number is so long, I want to assign its value to a variable called "id" on the JSP and use it.

My query is: Is there any technique of using the <s:set> tag to assign numeric value to the variable "id"? Or is it necessary that the value we are assigning should strictly be a String value?

Thanks & Regards,
John.




 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Johnnie Smith wrote:
The problem is with the set tag.


I don't think so. I have an a JSP like so:



And an action like so:


and it works fine (the first load of the page the value is 1567.65. Change the value in the text field, submit and the value is whatever you submitted). What are you doing different?


 
Johnnie Smith
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Joe.

I tried your page and it worked like a charm. Now my own page works fine too.

I do not know what went wrong earlier.

Anyway, Thank you very much.

Regards,
John.

 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
I guess everyone has an angle. Fine, what do you want? Just know that you cannot have this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic