The requested list key 'role' cocould not be resolved as a collection/array/MAP/enumerati

Source: Internet
Author: User

In a project where struts2 is applied, the following error is returned when you click Submit label on a page:

The
Requested list
Key 'role' cocould not be resolved as a collection/array/MAP/enumeration/iterator
Type

 

Check the prompt. The error message is a select tag, but the page is displayed as normal D. After troubleshooting, the action configuration related to this page is in the struts Configuration: error --> this page, that is, if an error is submitted, the page will still be returned. Because the Select data source is a request object, if an error is returned, no data is returned.

Summary:

The cause of this error may be as follows:

1. An error occurred when you first entered the interface because the set in list = "Roles" is empty, resulting in an error.

The solution is simple, and the list cannot be empty.

2. When you first enter the interface, the list contains data. When you click the submit button, the data is submitted to the background, if the verification framework is configured or the validate method is written in the action, the verification fails. If no action is taken, the input is directly returned and the interface is specified to be returned.
At this time, the list in the checkboxlist is lost, leading to the above error (this error prompt is unfriendly and is considered a class conversion error)

The solution is to put the list initialization work in the prepare interceptor, because prepare is executed before the validate interceptor, that is, the prepareble interface is implemented:

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.