This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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)
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).
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 ]
Joined: Jul 15, 2003
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...