• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp:setProperty Unexpected Behavior

 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I have a JavaBean with a float property and I'm trying to set it's property frm a JSP page using the following two variants.

1.
In the first case i'm passing a String constant


This works fine

2.
Next, i'm passing a request parameter


Here i get a fat java.lang.IllegalArgumentException: argument type mismatch, as the value is float and i'm passing a String, but wasn't this in the first case as well???

Pls...help...
 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Reema Patel:
Hello All,
I have a JavaBean with a float property and I'm trying to set it's property frm a JSP page using the following two variants.
1.
In the first case i'm passing a String constant

This works fine
2.
Next, i'm passing a request parameter

Here i get a fat java.lang.IllegalArgumentException: argument type mismatch, as the value is float and i'm passing a String, but wasn't this in the first case as well???
Pls...help...

No, your assumption that both cases are same is wrong.
For : "property="propertyName" value="{string | <%= expression %>}"


So your case 1, as long as the property is float,the string would be converted to float.

Further , If it is an expression, its value must have a data type that matches the data type of the Bean property.
[ October 10, 2006: Message edited by: vishwanath nadimpally ]
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think what you are actually after is


You can tell the JSP what parameter to populate the property from.
It should do the same as if you just provided it a String.
 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all!
It's working fine now...
<jsp:setProperty name="cart" property="price" value="<%=Float.parseFloat(request.getParameter("ePrice"))%>" />
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!