« Return to Thread: Custom value and Builder

Re: Custom value and Builder

by Alejandro Scandroli-2 :: Rate this Message:

Reply to Author | View in Thread

Hi

It's the GOF's Builder pattern http://en.wikipedia.org/wiki/Builder_pattern
First you need to implement this interface: org.trails.builder.Builder
It should as simple as:

public class InvoiceBuilder implements Builder<Invoice>
{

        public Invoice build()
        {
                Invoice invoice = new Invoice();
               // modify your invoice here
                return invoice;
        }
}


Then (this is the part that's missing in Trails 1.2) add your builder
to the BuilderDirector.
builderDirector.add(org.trails.demo.Invoice.class, new
InvoiceBuilder()); or something like this but using spring.

Again, there is currently no way to contribute builders to the
BuilderDirector's map, if you need it please rise a JIRA and I will
take care of this during the weekend.

Saludos.
Alejandro.

On Tue, Feb 3, 2009 at 1:22 AM, El Acuariano <acuariano@...> wrote:

> Hi all,
> I have a use case that I think should be quite common: I have several
> category type properties in my domain classes that generally should be
> selected from a predefined set but some times it need a custom value that
> doesn't fit the predefined ones. Is there a nice/recommended way of doing
> this? For example, lets say I have a domain class Address with a property
> Country. Normally all available countries would be selectable. But to be
> safe, I want to give users the chance to insert one. So, in the Address edit
> page, the user selects "Other" in the selection box and a text field shows
> where he can insert the unlisted country.
> Some time back I asked the following question:
>> - I need to fill-in an incremental invoice number. It should be editable
>> for
>> flexibility, but when creating a new invoice it should be initialized to
>> the
>> current invoice number. How can I set the initial value for a new invoice?
>
>
> And Alejandro's answer was:
>   There is a builder pattern implementation. But I just realize that
> in Trails 1.2.x there is no way to contribute your builder
> (org.trails.builder.Builder) to the builder director. Take a look at
> it (org.trails.builder.BuilderDirector), if that is what you need I
> can quickly fix it to allow contributions to the map.
>
> I don't really understand how to use it.
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 « Return to Thread: Custom value and Builder