FailedException method in ognl.OgnlRuntime.callAppropriateMethod

I have a working Action and JSP form that I use to create new objects in my most basic Struts 2.2.1.1 application. I am trying to modify an application to reuse the same JSP form for editing objects.

I have added a "hidden" identifier tag and now I get errors when I submit the form. Can someone please help me?

I looked for this problem and saw others posting similar errors, but I'm not sure how to resolve it.

Excerpt from Stack Trace when submitting a 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> 

FYI. I also submitted this question to the Struts-User mailing list, but received no input, so I will post it here as well. I will update another post and vice versa when more information appears.

+6
source share
5 answers

It is worth noting that stack tracing is a warning, not an error.

In addition, a warning is not generated when the form field is actually populated with a number. Only when it is empty (or presumably if it was filled with the actual string) is a warning and stack throw called. In fact, the Id field in the POJO model for the Action class is successfully populated with the value of the JSP form field if it is present (and, of course, of course).

Therefore, we can either ignore the Warning, because it does not do us any harm, or by default Id for some numerical value, and then add logic to our Action class to deal with it.

I decided to ignore the warning, and I changed my log4j level accordingly:

 # Struts OgnlUtil issues unimportant warnings log4j.logger.com.opensymphony.xwork2.util.OgnlUtil=error log4j.logger.com.opensymphony.xwork2.ognl.OgnlValueStack=error 

A more detailed discussion of this topic can be found on the Struts user mailing list: http://mail-archives.apache.org/mod_mbox/struts-user/201105.mbox/% 3CBANLkTinCzcTGjsn1jjotBr7fE_-5CX703w@mail.gmail.com % 3E

+2
source

Problem NoSuchMethodException ... ([Ljava.lang.String;)] can be caused by the presence of several attributes with the same name in the HTTP request.

If the case with multiple attributes with the same name is legal, you can handle multiple id values ​​by changing setId (int id) to setId (String [] idArray) and parsing each row of the array element as an integer.

Make sure that there is only one setId method (setId (String [] idArray)) in the action class. It seems some versions of struts / ognl (ognl 3.0.4?) Can get confused if there are several methods with the same name but with different types of parameters.

For instance:

 public void setId(String[] idArray) { for (String idString : idArray) { int id = Integer.parseInt(idString); ... handle different id values somehow ... } } 
+9
source

My guess is an old mistake. Try upgrading to the latest version of Ognl. Think maybe something. The latest version is on github. Searching there if you want to be very sure, but 2.7 should work, I think.

0
source

I think this is a hidden problem something like

this is if you have two pages and if the two hidden names have the same hidden name as shown below you will get an ognl error, delete 1 something like if you saved the hidden name on the first page and that the hidden name you are using on the second page, delete on the 2nd page (if the same hidden name is present) and run the program, now no error will be displayed. Why is this so, perhaps we are already hidden on the previous page and can be used on page 2 without hiding, with request.getParameter ("your name"); (Here the hidden variable is over-write). and one more, instead of giving input, hidden as input type, hidden, and gives the name and value that I think is best.

0
source

I also had the same bro.but error, I somehow found it 1. We do not need to define getter setter for the input field received from the jsp page, because it is automatically displayed based on the specified name. 2. Ensure that the field variables you pass in must not be repeated. 3. In my case, I make an ajax call with a field passed (for example: userId) and when the form is submitted (passing parameters also has userId). For this reason, the error has been reset. When I changed the name of the ajax call parameter as (ex: userIdTemp), it works well.

0
source

Source: https://habr.com/ru/post/887140/


All Articles