Ah....I never would of thought of that. I was under the impression that
submitting the option value from the select list would of been enough but it
appears I misjudged how the life cycle works. In any case, thank you so much
for pointing that out so quickly Dave.

I also had to implement prepare() on the HelloWorld action as well and paste
in the same init code for the Collection as I had with the CreateTicket
action. Without that implemented method and logic, I got the same error.

I'm going to write a wiki page on how to do this end to end validation with
these types of fields in the next few days because I found it kind of hard
to do with the existing documentation. I'll post the link once I write it.

Again many thanks Dave!


On Thu, Nov 27, 2008 at 5:29 PM, Dave Newton <[EMAIL PROTECTED]> wrote:

> You submit to HelloWorld, which doesn't have the list.
>
> Dave
>
> --- On Thu, 11/27/08, Mark Greene <[EMAIL PROTECTED]> wrote:
>
> > From: Mark Greene <[EMAIL PROTECTED]>
> > Subject: <s:select> tag causing could not be resolved as a
> collection/array/map/enumeration/iterator type error
> > To: user@struts.apache.org
> > Date: Thursday, November 27, 2008, 4:18 PM
> > Hi All,
> >
> > After a couple of days I can't seem to figure this
> > validation problem out. I
> > have a basic JSP form (create.jsp) with a textfield (with
> > validation) and a
> > select list (WITHOUT validation). When I submit the form to
> > trigger a
> > validation failure on purpose, the text field is validated
> > correctly and the
> > user input is still present, however, the select list
> > disappears below it
> > and the following error is given:
> >
> > ERROR [[default]] Servlet.service() for servlet default
> > threw exception
> > tag 'select', field 'list', name
> > 'catID': The requested list key
> > 'categories' could not be resolved as a
> > collection/array/map/enumeration/it
> > erator type. Example: people or people.{name} - [unknown
> > location]
> >
> > I've read about similar problems and they say to
> > initialize the collections
> > in the prepare(). I did that and I'm still getting the
> > problem. Another
> > solution I've heard was to put the Collection in the
> > session. This doesn't
> > seem like a scalable solution for applications that are
> > deployed in a
> > session replicated enviornement like clustering. Please
> > tell me that putting
> > the list in the seseion isn't the only work around?
> >
> >
> -----------------------------------------------------------------------------------------------------------
> > Action Code:
> >
> ------------------------------------------------------------------------------------------------------------
> > public class CreateTicket extends ActionSupport implements
> > Preparable {
> >
> >     private Map categories;
> >
> >     public Map getCategories() {
> >         return categories;
> >     }
> >
> >     public void setCategories(Map categories) {
> >         this.categories = categories;
> >     }
> >
> >     public String execute() throws Exception {
> >         this.prepare();
> >         return SUCCESS;
> >     }
> >
> >     public void prepare() throws Exception {
> >         categories = new HashMap();
> >         categories.put(1, "test");
> >         categories.put(2, "test2");
> >         categories.put(3, "test3");
> >     }
> > }
> >
> >
> > public class HelloWorld extends ActionSupport {
> >
> >     public static final String MESSAGE = "Struts is up
> > and running ...";
> >     private String name;
> >     private Integer catID;
> >
> >     public Integer getCatID() {
> >         return catID;
> >     }
> >
> >     public void setCatID(Integer catID) {
> >         this.catID = catID;
> >     }
> >
> >     public String execute() throws Exception {
> >
> >         setMessage(MESSAGE + " " + getName());
> >
> >         return SUCCESS;
> >
> >     }
> >
> >     private String message;
> >
> >     public void setMessage(String message) {
> >         this.message = message;
> >     }
> >
> >     public String getMessage() {
> >         return message;
> >     }
> >
> >     public String getName() {
> >         return name;
> >     }
> >
> >     public void setName(String name) {
> >         this.name = name;
> >     }
> >
> >
> ----------------------------------------------------------------------------------------------------------
> > /tutorial/create.jsp Code:
> >
> ----------------------------------------------------------------------------------------------------------
> > <s:form action="HelloWorld">
> > <s:textfield name="name" label="Your
> > name" size="50"/>
> > <s:select name="catID"
> > label="Categories"
> > list="categories"/>
> > <s:submit/>
> > </s:form>
> >
> >
> ----------------------------------------------------------------------------------------------------------
> > struts.xml Code:
> >
> ----------------------------------------------------------------------------------------------------------
> > <struts>
> >     <constant name="struts.action.extension"
> > value="" />
> >     <constant name="struts.devMode"
> > value="true" />
> >
> >     <package name="default"
> > extends="struts-default">
> >         <action name="create"
> > class="tutorial.CreateTicket">
> >             <result>/ticket/create.jsp</result>
> >         </action>
> >         <action name="HelloWorld"
> > class="tutorial.HelloWorld">
> >             <result
> > name="success">/ticket/createconfirm.jsp</result>
> >             <result
> > name="input">/ticket/create.jsp</result>
> >         </action>
> >     </package>
> > </struts>
> >
> >
> ----------------------------------------------------------------------------------------------------------
> > HelloWorld-validaiton.xml:
> >
> ----------------------------------------------------------------------------------------------------------
> > <validators>
> >     <validator type="stringlength">
> >         <param
> > name="fieldName">name</param>
> >         <param
> > name="minLength">10</param>
> >         <param
> > name="maxLength">10</param>
> >         <param
> > name="trim">true</param>
> >         <message>Your name needs to be 10 characters
> > long</message>
> >     </validator>
> > </validators>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to