Handle exception OGNL. Methodfailedexception setdate

Source: Internet
Author: User
Tags wrapper

The STRUTS2 has a default type of spin, and the base type can be converted:

Boolean and Boolean: The conversion between the complete string and the Boolean value;

Char and Character: complete the conversion between the string and the character;
int and integer: Converting between strings and shaping;
Long and long: a transformation between a string and an integer;
Flota and float: a conversion between the completion string and a single-precision floating-point value;
Double and double: complete the conversion of string and double-precision floating-point values;
Date: The conversion between the string and the date type is complete. ;
Arrays: Array elements are strings by default, and can be other composite type converters if the user provides a custom type converter;
Collections: By default, the collection element is assumed to be string and a new ArrayList is created to encapsulate all strings.

Exception 1, inside Struts2, when the page submits parameters to the server times OGNL. Methodfailedexception and Java.lang.NoSuchMethodException:setMoney ([Ljava.lang.String;)] exceptions, actually money is not a String type, but Float type or other type, but parameter values can still pass the past correctly.

Ognl. Methodfailedexception:method "Setmoney" failed for object com.yakoo5.cdhms.action.salemanageaction@221c75 [ Java.lang.NoSuchMethodException:setMoney ([Ljava.lang.String;)]

Workaround:

Modify the type of money to float type (wrapper type), and getter, the return type of the setter method, and the parameter type are modified to float. To resolve this issue.
Also, if you want to pass the parameter when the Struts2 of the Property object of the Action attribute, such as: SaleManageAction.SaleRecord.money, money is float type, it is best to change to float type, otherwise it will report the same error.

Recommendation: As long as the parameters passed from the page are the attributes of the Struts2 Action or the attributes of the Property object, they are changed from the original type (int,float,double) to the wrapper type (integer,float,double), of course their The parameters and return values of the setter and getter methods are also modified to the wrapper type, so that unnecessary exceptions of this type can be avoided.

Exception 2, date type conversion failed, warning message: Error setting expression ' Date ' with value ' [Ljava.lang.string;@1ee5b36 ' OGNL. Methodfailedexception:method "Setdate" failed for object com.shengsiyuan.struts2.loginaction@138b4ed [ Java.lang.NoSuchMethodException:

Workaround:

The reason for this is that the string value passed from the JSP page can be converted to the date type value at the end of 2011-10-10.
But the results can be "more correctly displayed," as follows:

After the query (http://www.iteye.com/problems/38729), learned that the problem is indeed in the JSP page input format, the correct format is: Month/day/year, such as (07/05/2012)
Now the output is:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.