About the Strutstypeconverter type converter

Source: Internet
Author: User

<!--
Question 1: How do I override the default error message?
1). New in the package where the corresponding Action class is located
Actionclassname.properties file, Actionclassname is the class name of the Action class that contains the input field
2). Add the following key-value pairs in the properties file: Invalid.fieldvalue.fieldname=xxx


2: If it is a simple theme, does it automatically display an error message? What if it doesn't show?
1). With the debug tag, if the conversion error occurs, there is a fielderrors attribute in the Action (implementing the Validationaware Interface) object of the value stack.
The type of the property is Map<string, list<string>>: Field (property name), Value: The error message consists of a List. So you can use the LE or OGNL way
To display the error message: ${fielderrors.age[0]}

2). You can also use the S:fielderror tab to display. You can display errors for the specified field through the FieldName property.

Question 3. If you have a simple theme and use <s:fielderror fieldname= "age" ></s:fielderror> to display an error message, the message is in a
UL, Li, span. How do I get rid of UL, Li, span?
The template.simple below FIELDERROR.FTL defines the style of the error message under the simple theme, S:fielderror label. So modify the
Configuration file. Create a new template.simple package under SRC, create a new FIELDERROR.FTL file, and put the contents of the native FIELDERROR.FTL
Copy to the new FIELDERROR.FTL, then reject the UL, Li, and span sections.

Question 4. How do I customize a type converter?
1). Why do I need a custom type converter? Because Struts cannot automatically complete the conversion of a string to a reference type.
2). How to define a type converter:
I. The class that develops the type converter: extends the Strutstypeconverter class.
II. Configure the type converter:
There are two ways of
①. Field-based configuration:
> Create a new modelclassname-conversion.properties file under the package of the Model (possibly an Action, possibly a JavaBean) where the field is located
> Enter a key-value pair in the file: The full class name of the Fieldname= type converter.
> Create an instance the first time you use the converter.
> type converters are single-instance!

②. Type-based configuration:
> New xwork-conversion.properties under SRC
> Type: The type to be converted = The full class name of the type converter.
> Creates an instance when the current STRUTS2 application is loaded.

-

About the Strutstypeconverter type converter

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.