Yes, CustomerEditor has:
public String getAsText()
{
Customer customer = (Customer) this.getValue();
String value = String.valueOf( customer.getId() );
return value;
}
Mike Horwitz wrote:
>
> That looks fine. I think the problem is more likely to be in the
> registering
> of the PropertyEditor in the Spring layer (it only knows about your object
> graph, and nothing at all about your database mappings). I have had a
> quick
> peek in the code, and it looks as if you have not implemented the
> getAsText() method for your editor?
>
> Mike
>
> On 10/17/07, George.Francis <[EMAIL PROTECTED]> wrote:
>>
>>
>> Application.getCustomer() returns a Customer instance. The reason
>> equals()
>> is being passed a
>> Long (I believe) is because I am mapping Application.customer to a
>> Customer
>> instance by it's id
>> in the Customer database table, i.e:
>>
>> @OneToOne(cascade = CascadeType.ALL)
>> @JoinColumn(name="customer_fk")
>> public Customer getCustomer()
>> {
>> return customer;
>> }
>>
>> where the customer_fk column is of type int8. Isn't this correct
>> procedure?
>>
>>
>> Mike Horwitz wrote:
>> >
>> > Looks like the Application.getCustomer() method is returning a Long? Is
>> > this
>> > possible? Spring MVC encourages the use of domain objects in the form,
>> so
>> > customers + Application.getCustomer() should both return Customer
>> objects.
>> >
>> > Mike
>> >
>> > On 10/16/07, George.Francis <[EMAIL PROTECTED]> wrote:
>> >>
>> >>
>> >> 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]
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Problemn-associating-entities-via-form-tf4616135s2369.html#a13254127
>> 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#a13258464
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]