This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSP and the fly likes beat problem with jsp:setProperty property= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "beat problem with jsp:setProperty property="*"" Watch "beat problem with jsp:setProperty property="*"" New topic
Author

beat problem with jsp:setProperty property="*"

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
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

Joined: Apr 25, 2004
Posts: 27
Remove the setWeight(int i) method with setWeight(String s) and change weight to String type in the bean class.


Thejaswi Narayana<br />SCJP 1.4<br />SCBCD 1.3<br />SCDJWS
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
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

Joined: Dec 11, 2004
Posts: 13410

You could also just wrap the setWeight method with one that takes a string argument.



Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jul 15, 2003
Posts: 618
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: beat problem with jsp:setProperty property="*"
 
Similar Threads
NullPointerException in JSP after calling Servlet method
Trouble writing to bean
Jsp Property question
EL displaying as text