1

I am using seam 2.2.2.Final on JBoss AS 5. I am working on a multi-page wizard.On my first page, user will be able to enter several business names separated by a new line on a textarea.

<s:decorate id="businessNameTextAreaField" template="layout/edit.xhtml">

                    <ui:define name="label">Business Names</ui:define>

                    <h:inputTextarea id="businessNameTextArea"

                                   cols="80"

                                   rows="3"

                               required="true"

                                  value="#{businessNameHome.instance.businessNameTextArea}"/>

            </s:decorate>

Upon submission of the page, the system parses the inputed value and splits it into a list of strings

      public String checkBusinessNames(){

            String businessNameTextArea = this.getInstance().getbusinessNameTextArea();

            String[] businessNameTextAreaArray = businessNameTextArea.split("\\n");



            List<SelectItem> businessNameChoices = new ArrayList<SelectItem>();



            for(String businessNameText: businessNameTextAreaArray){           

                businessNameChoices.add(new SelectItem(businessNameText));

            }



            this.getInstance().setBusinessNameChoices(businessNameChoices);

            return "valid";

      }

The user is then asked to select from the list of valid business names to register

<s:decorate id="businessNameRegisterListField" template="layout/edit.xhtml">

 <ui:define name="label">Business Name</ui:define>

 <h:selectManyCheckbox  value="#{businessNameHome.instance.selectedbusinessName}" layout="pageDirection" immediate="true" >

 <s:selectItems value="#{businessNameHome.instance.businessNameChoices}" var="bn" label="#{bn.label}" />                                                                                      </h:selectManyCheckbox>                            

  </s:decorate>

selectedbusinessName is of type String while businessNameChoices is of List

Upon submission of the page, what is submitted as business names is something like this:

javax.faces.model.SelectItem@135aa7c

I have tried putting an itemValue on the s:selectItems but I get another error which is "Value is not valid"

Tried to use <s:convertEntity> but gets a NumberFormatException

I have also tried to create my own converter

public class BusinessNameBeanConverter implements javax.faces.convert.Converter {

        @Override

        public Object getAsObject(FacesContext context, UIComponent cmp, String value)      {

            // TODO Auto-generated method stub

            System.out.println("getAsObject "+value);

            return value;

        }



        @Override

        public String getAsString(FacesContext context, UIComponent cmp, Object value) {

            // TODO Auto-generated method stub

            System.out.println("getAsString "+((SelectItem)value).getValue());

            return ((SelectItem)value).getValue();

        }



    }

but I still get the same "Value is not valid" error.

I don't know what to do anymore. Please help.

Thanks,

Nicholas

user1352297
  • 13
  • 1
  • 3

1 Answers1

3

Change

<s:selectItems value="#{businessNameHome.instance.businessNameChoices}" var="bn" label="#{bn.label}" />

to

<f:selectItems value="#{businessNameHome.instance.businessNameChoices}" />

You've namely already a List<SelectItem>, not a List<SomeObject> for which <s:selectItems> is useful.

Don't forget to remove the converter, it makes no sense.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hi BalusC. Thanks for the reply. I changed it to but im still getting the value is not valid error. I am running a long conversation as seen here Conversation: id = 5, long running. Thanks – user1352297 Apr 23 '12 at 22:55
  • My answer solves the problem of the values being displayed in `javax.faces.model.SelectItem@135aa7c` format. The "Validation error: value not valid" has a different cause. Please head to this answer to understand the cause: http://stackoverflow.com/questions/9069379/validation-error-value-is-not-valid/9069660#9069660 As it's `String`, the only cause can be that the list of selectitems has changed during form submit. – BalusC Apr 23 '12 at 23:03
  • Hi, thanks so much. I will visit that page and put a comment there :) – user1352297 Apr 24 '12 at 01:42