For the record I answer my own question:
Thomas Menke wrote:
> Hi,
>
> if have the following classes:
>
> abstract class Customer
> {
> public String name;
> abstract public getMaximumAllowedBooks();
> }
>
> class NormalCustomer extends Customer
> {
> public getMaximumAllowedBooks() { return 5; }
> }
>
> class VIPCustomer extends Customer
> {
> public String name;
> public getMaximumAllowedBooks() { return 50; }
> }
>
> The method getMaximumAllowedBooks() returns the number of books a
> Customer is allowed to lend in paralell.
> These classes are part of a program to manage a fictional library. It's
> not meant to make to much sense, it is just a learning application for me.
> Now I have a form for an administrator to add customers. He chooses the
> type of customer from a drop down menu and enters a name. The text field
> with the name is called "customer.name" for stripes to be able to auto
> populate the form and to bind the name to the customer immediately. The
> ActionBean of the form has a property
> "public Customer customer;".
> Additionally there is an enum type with all available classes:
> "public Customer.Type customerType;"
> Problem is: I need to instantiate customer based on the information in
> customerType. But before I can read customerType I can't instantiate the
> correct class because I don't know which type. And after the
> customerType has been set by stripes it is already too late because
> stripes already tried and failed to set the customer.name property.
>
> What would be the "best" way to deal with this?
Stripes populates the values in order of the length of the name of the
property. Thus I just need to make sure that this:
public Customer.Type customerType;
is shorter than that:
public Customer customer;
It is not right now, thus I rename customerType to cType. Then I use a
setter-method for cType which is guaranteed to be called prior to
setting any nested values of customer by stripes. In this method I
instantiate the correct sub class of Customer and assign it to customer.
And everything works fine.
Special thanks to bgunter&aporter for explaing that to me :-).
Thomas
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users