Do I have to change the equals() method too? Now I get the following on the
ApplicationForm:
[ismid] ERROR [http-8080-Processor25] OptionsTag.doStartTag(84) |
java.lang.Long cannot be cast to com.ism.ismid.model.Customer
java.lang.ClassCastException: java.lang.Long cannot be cast to
com.ism.ismid.model.Customer
at com.ism.ismid.model.Customer.equals(Customer.java:35)
at
org.springframework.util.ObjectUtils.nullSafeEquals(ObjectUtils.java:170)
at
org.springframework.web.servlet.tags.form.SelectedValueComparator.isSelected(SelectedValueComparator.java:90)
at
org.springframework.web.servlet.tags.form.OptionWriter.isSelected(OptionWriter.java:184)
at
org.springframework.web.servlet.tags.form.OptionWriter.renderOption(OptionWriter.java:172)
George.Francis wrote:
>
> Would that be ApplicationFormController's initBinder method?
> This is my setAsText method:
>
> public void setAsText(String text) throws IllegalArgumentException
> {
> Customer obj;
> if (text == null || text.length() == 0) {
> setValue(null);
> } else {
> obj = new Customer();
> obj.setId(Long.parseLong(text));
> setValue(obj);
> }
> }
>
>
>
> Mike Horwitz wrote:
>>
>> On 10/15/07, George.Francis <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>> OK, after reading this I assume I need to define a class
>>> ApplicationBeanInfo
>>> which extends SimpleBeanInfo, whose getPropertyDescriptors() method uses
>>> a
>>> class CustomerEditor (which I also have to write) which extends
>>> PropertyEditor?
>>
>>
>> Not quite. You only need to write a CustomerEditor (easiest way is by
>> extending PropertyEditorSupport and overriding the getAsText() and
>> setAsText() methods) which you register in your controller using the
>> initBinder() method: http://tinyurl.com/2sutrm
>>
>> Mike
>>
>> mraible wrote:
>>> >
>>> > You need a PropertyEditor to translate the "id" that's coming for
>>> > Customer to a real customer object from your database.
>>> >
>>> > http://www.springframework.org/docs/reference/validation.html
>>> >
>>> > Matt
>>> >
>>> > On 10/12/07, George.Francis <[EMAIL PROTECTED]> wrote:
>>> >>
>>> >> Hi, I have two entities in my Spring MVC app, 'Application' and
>>> >> 'Customer'.
>>> >> The Application edit form has a drop-down list of Customers so that
>>> one
>>> >> can
>>> >> be associated with the Application. THis is done via the following
>>> tags
>>> >> in
>>> >> the JSP;
>>> >>
>>> >> <form:select path="customer">
>>> >> <form:options items="${customers}" itemValue="id"
>>> >> itemLabel="name"/>
>>> >> </form:select>
>>> >>
>>> >> When I submit the form I get a validation error:
>>> >> "Failed to convert property value of type [java.lang.String] to
>>> required
>>> >> type [com.ism.ismid.model.Customer] for property customer; nested
>>> >> exception
>>> >> is java.lang.IllegalArgumentException: Cannot convert value of type
>>> >> [java.lang.String] to required type [com.ism.ismid.model.Customer]
>>> for
>>> >> property customer: no matching editors or conversion strategy found"
>>> >>
>>> >> Can someone see why this is happening?
>>> >>
>>> >>
>>> >> --
>>> >> View this message in context:
>>> >>
>>> http://www.nabble.com/Problemn-associating-entities-via-form-tf4616135s2369.html#a13183354
>>> >> Sent from the AppFuse - User mailing list archive at Nabble.com.
>>> >>
>>> >> ---------------------------------------------------------------------
>>> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> >> For additional commands, e-mail: [EMAIL PROTECTED]
>>> >>
>>> >>
>>> >
>>> >
>>> > --
>>> > http://raibledesigns.com
>>> >
>>> > ---------------------------------------------------------------------
>>> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> > For additional commands, e-mail: [EMAIL PROTECTED]
>>> >
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Problemn-associating-entities-via-form-tf4616135s2369.html#a13214827
>>> Sent from the AppFuse - User mailing list archive at Nabble.com.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/Problemn-associating-entities-via-form-tf4616135s2369.html#a13242743
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]