*
The moose likes Struts and the fly likes set tag not working for numeric data types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "set tag not working for numeric data types" Watch "set tag not working for numeric data types" New topic
Author

set tag not working for numeric data types

Johnnie Smith
Greenhorn

Joined: May 02, 2012
Posts: 22
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.


Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8839
    
    7

The documentation for the set tag says it sets a variable to a value. You are setting "identification_number" to a string value.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Johnnie Smith
Greenhorn

Joined: May 02, 2012
Posts: 22
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

Joined: Oct 29, 2001
Posts: 8839
    
    7

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

Joined: May 02, 2012
Posts: 22
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

Joined: Oct 29, 2001
Posts: 8839
    
    7

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

Joined: May 02, 2012
Posts: 22
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

Joined: Oct 29, 2001
Posts: 8839
    
    7

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: set tag not working for numeric data types
 
Similar Threads
iterate
Double Validation problem in Struts
type converson failed in struts 2 : ognl.MethodFailedException
Search form, html:option, MySql?! :o(
scriplet in html:select tag