> If there's a validation error, the input page will be displayed.
>
> If the input page is being displayed, the JSP references the list.
>
> If the JSP references the list, it's needed.
>
> If the JSP page isn't being displayed, you cannot get the error
> message your getting.

I totally agree with your analysis of the operation of a validation error 
/ input page. I don't believe that's what is happening though. I ran 
Struts in debug mode and stepped through where it was getting tripped up 
and it fails very early in the cycle, when it is reading the JSP. It gets 
to the select list and expects to find a collection and immediately the 
page fails. This is before it has anything to do with the target action 
and I believe it is before validation. It is in ListUIBean.
evaluateExtraParams:
        if (list instanceof String) {
            value = findValue((String) list);
...
        if (value == null) {
            if (throwExceptionOnNullValueAttribute) {
                // will throw an exception if not found
                value = findValue((list == null) ? (String) list : 
list.toString(), "list",
                    "The requested list key '" + list + "' could not be 
resolved as a collection/array/map/enumeration/iterator type. " +
                    "Example: people or people.{name}");
            }

Value is null, so I get the exception.

------------
I have sample code I downloaded on validations and I've modified it to 
simulate. I don't know if attachments come through. I'm attaching it, but 
I'll also explain it with some snippets.

The Action class:
public class RegisterAction extends ActionSupport implements Preparable {

Fields:
        private User user;
        private List<Gender> genderList;

Methods (some skipped for brevity):

        public String list() {
                populateGenderList();
                return Action.SUCCESS;
        }

        private void populateGenderList() {
                genderList = new ArrayList<Gender>();
                Gender gender = new Gender();
                gender.setCode("M");
                gender.setDescription("Male");
                genderList.add(gender);
                gender = new Gender();
                gender.setCode("F");
                gender.setDescription("Female");
                genderList.add(gender);
        }

        public String add() throws Exception {
                System.out.println(user);
                return Action.SUCCESS;
        }

        public void prepare() throws Exception {
                //populateGenderList();
        }

Of course, the select list is on gender.

The mapping points to list() to display the form. It has another one to 
point to add() and the form points there.

With prepare() contents commented, I get the 
"throwExceptionOnNullValueAttribute" during the add(). If I uncomment, it 
works. If I take out the validation file and remove prepare(), it works.

Yes, I know that I can put populateGenderList() in prepare and remove it 
from list() - not a production app., just a demonstration. Also, I'm 
trying to avoid populating the list during add() as it is unnecessary.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to