Thanks! protected Address address = new Address() did the trick!

Troy

On Tue, 2005-13-09 at 19:42 +0200, Eelco Hillenius wrote:
> In the end, (Bound)CompoundPropertyModels are IModels. IModel just has
> get/setObject, where you can implement anything you want, including
> object creation etc.
> 
> CompoundPropertyModels are meant to make your life easier in the sense
> that you need less code to acchieve model/property binding. The basis
> however, is PropertyModel. WIth PropertyModel you can bind anything
> you want, as long as it is a valid two-way Ognl expression.
> 
> IModel clientFormModel = new CompoundPropertyModel(myClient);
> setModel(clientFormModel);
> add(new TextField("address.streetAddress");
> 
> is the same as:
> 
> BoundCompoundPropertyModel clientFormModel = new
> BoundCompoundPropertyModel(myClient);
> setModel(clientFormModel);
> add(clientFormModel.bind(new TextField("nonImportantName"),
> "address.streetAddress"));
> 
> is the same as:
> 
> add(new TextField("nonImportantName", new PropertyModel(myClient,
> "address.streetAddress"));
> 
> Now, the problem with your code is that the address is null by
> default. Ognl doesn't like that, and will throw an exception. There
> are a zillion ways to tackle this, including patching Ognl, patching
> PropertyModel, etc, but the simplest way to go here is to make sure
> you allways have a non-null address property. Either by declaring that
> property like 'protected Address address = new Address;' - your ORM
> will overwrite that field when it does have a saved value - or lazily
> create an instance in your getter - in which case you must make sure
> the getter is not by-passed by any code generation your ORM might do
> for you.
> 
> I don't think you need the converter; it will work in some cases, and
> for some custom object they can be very convenient/ elegant, but in
> this case, the fact that your property can be null and Ognl doesn't
> try object creation is the real issue.
> 
> Eelco
> 
> 
> 
> On 9/13/05, Troy MacNeil <[EMAIL PROTECTED]> wrote:
> > This is ultimately what I want. The Client object will have a collection
> > of addresses, invoices and other objects. The user can view these
> > objects and add new ones.
> > 
> > - I can create a form to create a new Client.
> > 
> > - I can create a form to add an address to an existing Client (at least
> > I think I can;)
> > 
> > - I can't create a form to create a Client and add an Address at the
> > same time. Right now I get bind errors if I add fields that aren't
> > properties of the Client object itself.
> > 
> > I suspect the solution lies with the property model. My current code
> > references Client directly:
> > 
> > IModel clientFormModel = new CompoundPropertyModel(new Client());
> > 
> > But I don't have a clear enough understanding of how Compound and Bound
> > property models work.
> > 
> > Thanks,
> > Troy
> > 
> > 
> > On Tue, 2005-13-09 at 09:15 -0700, Igor Vaynberg wrote:
> > > I think a good way to handle this would be to use two pages. First page
> > > would show the form for the client object properties along with properties
> > > for a single address, the second page would allow the user to add 
> > > additional
> > > addresses to the client object they created in the previous step. Almost
> > > like a two page wizard.
> > >
> > > -Igor
> > >
> > >
> > > > -----Original Message-----
> > > > From: [EMAIL PROTECTED] [mailto:wicket-user-
> > > > [EMAIL PROTECTED] On Behalf Of Troy MacNeil
> > > > Sent: Tuesday, September 13, 2005 8:24 AM
> > > > To: [email protected]
> > > > Subject: [Wicket-user] Creating Embedded Object via Form
> > > >
> > > > This isn't the brightest question I've ever asked, I feel I'm missing
> > > > very obvious. But I don't see an answer in the examples/wiki so here
> > > > goes...
> > > >
> > > > I'm wondering how to handle. So for instance if I have a Client object
> > > > which has one or more Address objects as members, how can I create a new
> > > > client using a single form?
> > > >
> > > > I've looked at the cdapp example where Categories are linked to Albums,
> > > > what I want is similar except I'd like to create Categories on the fly
> > > > if necessary rather than select from a pre-instantiated list.
> > > >
> > > > <form wicket:id="form" action="">
> > > > Name:
> > > > <input type="text"  wicket:id="firstName"><br/>
> > > > Street Address:
> > > > <input type="text"  wicket:id="address.streetAddress"><br/>
> > > > <input type="submit" value="Add Client"/>
> > > > </form>
> > > >
> > > > @Entity
> > > > public class Client implements Comparable<Client> {
> > > >     protected Long Id;
> > > >     protected String Name;
> > > >     protected Address address;
> > > >
> > > >     /*typical getters/setters below */
> > > > }
> > > >
> > > > @Entity
> > > > public class Address implements Comparable<Address> {
> > > >     protected Long Id;
> > > >     protected String streetAddress;
> > > >
> > > >     /*typical getters/setters below */
> > > > }
> > > >
> > > > Any help or pointers in the right direction greatly appreciated...
> > > >
> > > > Thanks,
> > > > Troy
> > > >
> > > > Alluvion Development
> > > > http://alluvioncorp.com
> > > >
> > > >
> > > > -------------------------------------------------------
> > > > SF.Net email is Sponsored by the Better Software Conference & EXPO
> > > > September 19-22, 2005 * San Francisco, CA * Development Lifecycle
> > > > Practices
> > > > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & 
> > > > QA
> > > > Security * Process Improvement & Measurement * 
> > > > http://www.sqe.com/bsce5sf
> > > > _______________________________________________
> > > > Wicket-user mailing list
> > > > [email protected]
> > > > https://lists.sourceforge.net/lists/listinfo/wicket-user
> > > >
> > >
> > >
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > SF.Net email is Sponsored by the Better Software Conference & EXPO
> > > September 19-22, 2005 * San Francisco, CA * Development Lifecycle 
> > > Practices
> > > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
> > > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
> > > _______________________________________________
> > > Wicket-user mailing list
> > > [email protected]
> > > https://lists.sourceforge.net/lists/listinfo/wicket-user
> > >
> > 
> > 
> > -------------------------------------------------------
> > SF.Net email is Sponsored by the Better Software Conference & EXPO
> > September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
> > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
> > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
> > _______________________________________________
> > Wicket-user mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/wicket-user
> >
> 
> 
> -------------------------------------------------------
> SF.Net email is Sponsored by the Better Software Conference & EXPO
> September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
> _______________________________________________
> Wicket-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
> 


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to