ClassCastException in ListMultipleChoice

2009-09-22 Thread Sadhna Ahuja
Hello,

 

I have a ListMultipleChoice component in my form and I get the following
exception when I select an option and submit the form:

 

Caused by: java.lang.ClassCastException: java.lang.String cannot be cast
to java.util.Collection

  at
org.apache.wicket.markup.html.form.ListMultipleChoice.updateModel(ListMu
ltipleChoice.java:325)

  at
org.apache.wicket.markup.html.form.Form$20.validate(Form.java:1837)

  at
org.apache.wicket.markup.html.form.Form$ValidationVisitor.formComponent(
Form.java:165)

  at
org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPost
OrderHelper(FormComponent.java:421)

  at
org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPost
OrderHelper(FormComponent.java:408)

  at
org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPost
Order(FormComponent.java:385)

  at
org.apache.wicket.markup.html.form.Form.visitFormComponentsPostOrder(For
m.java:1060)

  at
org.apache.wicket.markup.html.form.Form.internalUpdateFormComponentModel
s(Form.java:1829)

  at
org.apache.wicket.markup.html.form.Form.updateFormComponentModels(Form.j
ava:1796)

  at org.apache.wicket.markup.html.form.Form.process(Form.java:865)

  at
org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:807)

  ... 53 more

 

Could someone please point out if I'm missing something? Here's the
relevant pieces of my code:

--

ListMultipleChoice searchPymntApplCd = new
ListMultipleChoice(

searchPymntApplCd,

new AbstractReadOnlyModel() {

public Object getObject() {

return getPaymentApplOptions(paymentAppls);
//This returns ArrayListPaymentApplOption

}},

new IChoiceRenderer() {

public Object getDisplayValue(Object object) {

PaymentApplOption option =
(PaymentApplOption) object;

return option.getPymntApplDesc();

}

public String getIdValue(Object object, int
index) {

if
(PaymentApplOption.class.isInstance(object)) {

PaymentApplOption option =
(PaymentApplOption) object;

return option.getPymntApplCd();

}

return null;

}

}).setMaxRows(5);

searchPymntApplCd.setRequired(false);

searchPymntApplCd.setType(Collection.class);

add(searchPymntApplCd);

 

---

public class PaymentApplOption implements Serializable {

 

private String pymntApplCd;

private String pymntApplDesc;

...

}

 

Thanks.

 

 

 



Re: ClassCastException in ListMultipleChoice

2009-09-22 Thread Igor Vaynberg
your model object should be a collection instead of a string because
this component allows selection of multiple values.

-igor

On Tue, Sep 22, 2009 at 6:37 AM, Sadhna Ahuja sadhna.ah...@nisc.coop wrote:
 Hello,



 I have a ListMultipleChoice component in my form and I get the following
 exception when I select an option and submit the form:



 Caused by: java.lang.ClassCastException: java.lang.String cannot be cast
 to java.util.Collection

      at
 org.apache.wicket.markup.html.form.ListMultipleChoice.updateModel(ListMu
 ltipleChoice.java:325)

      at
 org.apache.wicket.markup.html.form.Form$20.validate(Form.java:1837)

      at
 org.apache.wicket.markup.html.form.Form$ValidationVisitor.formComponent(
 Form.java:165)

      at
 org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPost
 OrderHelper(FormComponent.java:421)

      at
 org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPost
 OrderHelper(FormComponent.java:408)

      at
 org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPost
 Order(FormComponent.java:385)

      at
 org.apache.wicket.markup.html.form.Form.visitFormComponentsPostOrder(For
 m.java:1060)

      at
 org.apache.wicket.markup.html.form.Form.internalUpdateFormComponentModel
 s(Form.java:1829)

      at
 org.apache.wicket.markup.html.form.Form.updateFormComponentModels(Form.j
 ava:1796)

      at org.apache.wicket.markup.html.form.Form.process(Form.java:865)

      at
 org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:807)

      ... 53 more



 Could someone please point out if I'm missing something? Here's the
 relevant pieces of my code:

 --

            ListMultipleChoice searchPymntApplCd = new
 ListMultipleChoice(

                searchPymntApplCd,

                    new AbstractReadOnlyModel() {

                        public Object getObject() {

                            return getPaymentApplOptions(paymentAppls);
 //This returns ArrayListPaymentApplOption

                        }},

                    new IChoiceRenderer() {

                        public Object getDisplayValue(Object object) {

                            PaymentApplOption option =
 (PaymentApplOption) object;

                            return option.getPymntApplDesc();

                        }

                        public String getIdValue(Object object, int
 index) {

                            if
 (PaymentApplOption.class.isInstance(object)) {

                                PaymentApplOption option =
 (PaymentApplOption) object;

                                return option.getPymntApplCd();

                            }

                            return null;

                        }

                    }).setMaxRows(5);

            searchPymntApplCd.setRequired(false);

            searchPymntApplCd.setType(Collection.class);

            add(searchPymntApplCd);



 ---

 public class PaymentApplOption implements Serializable {



    private String pymntApplCd;

    private String pymntApplDesc;

    ...

 }



 Thanks.









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



ClassCastException in ListMultipleChoice

2009-09-21 Thread Sadhna Ahuja
Hello,

 

I have a ListMultipleChoice component in my form and I get the following
exception when I select an option and submit the form:

 

Caused by: java.lang.ClassCastException: java.lang.String cannot be cast
to java.util.Collection

  at
org.apache.wicket.markup.html.form.ListMultipleChoice.updateModel(ListMu
ltipleChoice.java:325)

  at
org.apache.wicket.markup.html.form.Form$20.validate(Form.java:1837)

  at
org.apache.wicket.markup.html.form.Form$ValidationVisitor.formComponent(
Form.java:165)

  at
org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPost
OrderHelper(FormComponent.java:421)

  at
org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPost
OrderHelper(FormComponent.java:408)

  at
org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPost
Order(FormComponent.java:385)

  at
org.apache.wicket.markup.html.form.Form.visitFormComponentsPostOrder(For
m.java:1060)

  at
org.apache.wicket.markup.html.form.Form.internalUpdateFormComponentModel
s(Form.java:1829)

  at
org.apache.wicket.markup.html.form.Form.updateFormComponentModels(Form.j
ava:1796)

  at org.apache.wicket.markup.html.form.Form.process(Form.java:865)

  at
org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:807)

  ... 53 more

 

Could someone please point out if I'm missing something? Here's the
relevant pieces of my code:

--

ListMultipleChoice searchPymntApplCd = new
ListMultipleChoice(

searchPymntApplCd,

new AbstractReadOnlyModel() {

public Object getObject() {

return getPaymentApplOptions(paymentAppls);
//This returns ArrayListPaymentApplOption

}},

new IChoiceRenderer() {

public Object getDisplayValue(Object object) {

PaymentApplOption option =
(PaymentApplOption) object;

return option.getPymntApplDesc();

}

public String getIdValue(Object object, int
index) {

if
(PaymentApplOption.class.isInstance(object)) {

PaymentApplOption option =
(PaymentApplOption) object;

return option.getPymntApplCd();

}

return null;

}

}).setMaxRows(5);

searchPymntApplCd.setRequired(false);

searchPymntApplCd.setType(Collection.class);

add(searchPymntApplCd);

 

---

public class PaymentApplOption implements Serializable {

 

private String pymntApplCd;

private String pymntApplDesc;

...

}

 

Thanks.