When you try and convert null to a primitive type an exception will be thrown, however Struts has code to handle this so it just gives you a warning. Best solution is to default the value or make sure you supply a value for your hidden field and base your application logic on this value. Action class: if myObj.getTagId() < 0 Not Editing. else Editing end >> public class Tag implements java.io.Serializable { >> >> >> private int tagId = -1; >> >> public int getTagId() { >> return this.tagId; >> } >> >> public void setTagId(int tagId) { >> this.tagId = tagId; >> } >>> <jlm...@gmail.com> 5/3/2011 9:16 AM >>> Well, if there the field is empty, I understand that OGNL will try to match ““ to the field, so it will look for a setter that receives a String. Sent via BlackBerry from T-Mobile
-----Original Message----- From: Justin Robbins <justinhrobb...@gmail.com> Date: Tue, 3 May 2011 09:11:09 To: Struts Users Mailing List<user@struts.apache.org> Reply-To: "Struts Users Mailing List" <user@struts.apache.org> Subject: Re: help with MethodFailedException in ognl.OgnlRuntime.callAppropriateMethod Hi Eric, You are pointing out the error? Here's the thing, and hopefully you can set me straight here, I acknowledge there is no setTagId([Ljava.lang.String;)]. After all, "tagId" is an integer in my POJO. Why would I have a method for it that accepts a String? I'm still getting up to speed on OGNL but shouldn't it be converting the form field to an integer for me (assuming the form field has a value at all)? Also, the "tagId" is indeed getting set successfully (and without the stack trace in the log) when i submit a form that has a value in that field. It seems to only throw the error (warning) when the form field is submitted empty. Just to review, I'm reusing the same JSP form for the creation of new Tag entities and the editing of existing Tags. There's a hidden form field "tagId" that is only populated with a value when I'm editing an existing Tag entity. Thanks much for your input. It's appreciated. If there is something wrong with the way I'm going about things then please feel free to set me straight. Justin On Tue, May 3, 2011 at 8:37 AM, Eric Reed <ere...@mail.nysed.gov> wrote: > Justin, > > Your error: >> [java.lang.NoSuchMethodException: >> org.robbins.flashcards.model.Tag.setTagId([Ljava.lang.String;)] <<----STRING > >> public void setTagId(int tagId) { <-- INT >> this.tagId = tagId; >> } > Eric Reed > NYS Education Department > > >>>> Justin Robbins <justinhrobb...@gmail.com> 5/3/2011 8:32 AM >>> > Since the stack trace is at Warn level and doesn't actually seem to be > breaking my code then maybe I'm best off just adjusting the log4j > level higher for the Ognl related packages? > > # Struts OgnlUtil issues unimportant warnings > log4j.logger.com.opensymphony.xwork2.util.OgnlUtil=error > log4j.logger.com.opensymphony.xwork2.ognl.OgnlValueStack=error > > On Mon, May 2, 2011 at 9:27 PM, Justin Robbins <justinhrobb...@gmail.com> wrote: >> Nope, my bad. After a full refactor I get the same error. Below are >> snippets of the new code and most recently generated error. >> >> Stack Trace excerpt: >> 2011-05-02 21:24:49,887 175361 ["http-bio-8080"-exec-7] WARN >> com.opensymphony.xwork2.ognl.OgnlValueStack - Error setting expression >> 'tagId' with value '[Ljava.lang.String;@1e73e0d' >> ognl.MethodFailedException: Method "setTagId" failed for object >> org.robbins.flashcards.model.Tag@144dc7b [name='my tag' ] >> [java.lang.NoSuchMethodException: >> org.robbins.flashcards.model.Tag.setTagId([Ljava.lang.String;)] >> at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1285) >> at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1474) >> >> JSP excerpt: >> <s:form action="saveOrUpdateTag" method="post"> >> <s:hidden name="tagId" /> >> <s:textfield name="name" key="label.tag.name" size="20" /> >> <s:submit label="label.flashcard.submit" align="center" /> >> </s:form> >> >> POJO excerpt: >> public class Tag implements java.io.Serializable { >> >> >> private int tagId; >> >> public int getTagId() { >> return this.tagId; >> } >> >> public void setTagId(int tagId) { >> this.tagId = tagId; >> } >> >> On Mon, May 2, 2011 at 8:53 PM, Justin Robbins <justinhrobb...@gmail.com> wrote: >>> I tested it just now and I do NOT get the error when I refactor the >>> code from the POJO on down to the JSP to use "myId" instead of "id". >>> >>> On Mon, May 2, 2011 at 8:43 PM, Dave Newton <davelnew...@gmail.com> wrote: >>>> Just out of curiosity, does it do the same thing if it's not named "id"? >>>> >>>> d. >>>> >>>> On Mon, May 2, 2011 at 8:32 PM, Justin Robbins <justinhrobb...@gmail.com> wrote: >>>>> Anyone have any ideas on this one? I'd be most grateful for some advice. >>>>> >>>>> Someone suggested I use a newer version of the ognl jar. I was using >>>>> "ognl-3.0.jar" which is what came with the Struts 2.2.1.1 >>>>> distribution. I've since replaced it with "ognl-3.0.1.jar" but I'm >>>>> still receiving the same error. >>>>> >>>>> Any help is greatly appreciated. >>>>> >>>>> On Mon, May 2, 2011 at 11:26 AM, Justin Robbins >>>>> <justinhrobb...@gmail.com> wrote: >>>>>> Hi folks, >>>>>> >>>>>> I have a working Action and JSP form that I'm using for creating new >>>>>> entities in my very basic Struts 2.2.1.1 app. I'm trying to modify >>>>>> the app to re-use the JSP form with editing of entities. I added a >>>>>> hidden "ID" tag and now I'm getting errors when I submit the form. >>>>>> Can someone please give me some assistance? I've Googled this issue >>>>>> and seen others posting similar errors but I'm not sure how to resolve >>>>>> it. >>>>>> >>>>>> Excerpt from Stack Trace when I submit the form: >>>>>> 2011-05-02 11:09:36,132 3198497 ["http-bio-8080"-exec-23] WARN >>>>>> com.opensymphony.xwork2.ognl.OgnlValueStack - Error setting expression >>>>>> 'id' with value '[Ljava.lang.String;@100ac03' >>>>>> ognl.MethodFailedException: Method "setId" failed for object >>>>>> org.robbins.flashcards.model.Tag@1b9eb34 [name='null' ] >>>>>> [java.lang.NoSuchMethodException: >>>>>> org.robbins.flashcards.model.Tag.setId([Ljava.lang.String;)] >>>>>> at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1285) >>>>>> at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1474) >>>>>> >>>>>> Excerpt from JSP: >>>>>> <%@ taglib prefix="s" uri="/struts-tags"%> >>>>>> ... >>>>>> <s:form action="saveOrUpdateTag" method="post"> >>>>>> <s:hidden name="id" /> >>>>>> <s:textfield name="name" key="label.tag.name" size="20" /> >>>>>> <s:submit label="label.flashcard.submit" align="center" /> >>>>>> </s:form> >>>>>> >>>>>> Excerpt from Action Class: >>>>>> public class TagAction extends FlashCardsAppBaseAction implements >>>>>> ModelDriven<Tag> { >>>>>> >>>>>> Tag tag = new Tag(); >>>>>> >>>>>> public Tag getTag() { >>>>>> return tag; >>>>>> } >>>>>> >>>>>> public void setTag(Tag tag) { >>>>>> this.tag = tag; >>>>>> } >>>>>> public String createTag() { >>>>>> ... >>>>>> } >>>>>> } >>>>>> >>>>>> Excerpt from POJO: >>>>>> public class Tag implements java.io.Serializable { >>>>>> >>>>>> >>>>>> private int id; >>>>>> private String name; >>>>>> >>>>>> public int getId() { >>>>>> return this.id; >>>>>> } >>>>>> >>>>>> public void setId(int id) { >>>>>> this.id = id; >>>>>> } >>>>>> ... >>>>>> } >>>>>> >>>>>> Excerpt from Struts.xml >>>>>> <action name="saveOrUpdateTag" >>>>>> class="org.robbins.flashcards.presentation.TagAction" >>>>>> method="createTag"> >>>>>> <result name="success" type="tiles">displaytag.tiles</result> >>>>>> <result name="input" type="tiles">tagform.tiles</result> >>>>>> </action> >>>>>> >>>>>> -- >>>>>> Regards, >>>>>> Justin >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >>>>> For additional commands, e-mail: user-h...@struts.apache.org >>>>> >>>>> >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >>>> For additional commands, e-mail: user-h...@struts.apache.org >>>> >>>> >>> >>> >>> >>> -- >>> >> >> >> >> -- > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org