Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

beat problem with jsp:setProperty property="*"

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My JSP has the following line at the top:



One of the form fields is weight, and the bean has a weight field, and setProperty sets it with the bean's setWeight(int i) method. However, if I put the letter c into the field, Tomcat/Jasper spits out the error message you see at the bottom. I've been trying to figure out a workaround to this. I've tried adding a method setWeight(String s) to the bean to try to intercept this, and I've tried intercepting it at the beginning of the post-handling code, but even at that point setProperty has already called the setWeight(int i) method, so it throws up all over itself. Is there any way to get around this without relying on client-side scripting? Thanks...


org.apache.jasper.JasperException: For input string: "c"
at org.apache.jasper.runtime.JspRuntimeLibrary.internalIntrospecthelper(JspRuntimeLibrary.java:274)
at org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:220)
at org.apache.jasper.runtime.JspRuntimeLibrary.introspect(JspRuntimeLibrary.java:198)
at org.apache.jsp.CreateShipment_jsp._jspService(CreateShipment_jsp.java:117)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 
Thejaswi Narayana
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove the setWeight(int i) method with setWeight(String s) and change weight to String type in the bean class.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I wish it had been done that way originally. There's tons of code that depends on that, so I'll break down and use JavaScript. :roll:
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also just wrap the setWeight method with one that takes a string argument.

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried that, but the weight property is used throughout the system, and so the Tomcat/Jasper thingie that calls jsp:setProperty property="*" looks for the long-established setWeight(int i) method (I tried giving the POJO a setWeight(String s) method that calls the setWeight(int i) method, but apparently that didn't work for some reason--it still tried to call the setWeight(int i) method right away (and I really don't know why, since so many other methods like this take a String argument).
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the code to your setWeight method?
I was just looking at JSP1-11 and according to it, you shouldn't even need to wrap the method. The jsp:setProperty tag should handle this for you:

[ May 25, 2005: Message edited by: Ben Souther ]
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the setWeight(int i) method that's been around forever:



I just tried adding something like that, but it still kept spewing out the error above as if it didn't notice my new method:



And yeah, I tried it with Float and other stuff like that, but the point is it seemed to favor my setWeight(int i) method for some reason. I know that auto-setting of properties is something I shouldn't totally rely on in all circumstances, so I'm content to just deal with it...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic