Not entirely sure what your logic needs to be, but the normal approach would
be to associate your Application object with a pre-existing customer from
the database. So your method would look more like (I have also changed the
code to use commons lang, personal preference :-):

       public void setAsText(String text) throws IllegalArgumentException
       {
               Customer obj;
               if (StingUtils.isEmpty(text) || !StingUtils.isNumeric(text))
{
                       setValue(null);
               } else {
                       obj = customerManager.get(Long.parseLong(text));
                       setValue(obj);
               }
       }

Mike

On 10/16/07, George.Francis <[EMAIL PROTECTED]> 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#a13242679
> Sent from the AppFuse - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to