« Return to Thread: Custom value and Builder

Re: Custom value and Builder

by El Acuariano :: Rate this Message:

Reply to Author | View in Thread

Thanks! It works fine!


On Fri, Feb 13, 2009 at 9:59 AM, Alejandro Scandroli <ascandroli@...> wrote:
Hi HernĂ¡n

Check the checkin: http://fisheye.codehaus.org/changelog/trails?cs=1071
You will have to modify your applicationContext.xml and hivemodule.xml
to reflect the changes:
http://fisheye.codehaus.org/browse/trails/branches/trails-1.2.x/examples/recipe/src/main/resources/applicationContext.xml?r1=963&r2=1071
http://fisheye.codehaus.org/browse/trails/branches/trails-1.2.x/archetypes/trails-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/hivemodule.xml?r1=963&r2=1071

Then contribute your builder in your applicationContext.xml

<bean id="builderDirector" class="org.trails.builder.BuilderDirectorImpl">
 <property name="builders">
   <map>
     <entry>
       <key>
         <value>com.yourpackage.entities.Invoice/value>
       </key>
       <bean class="org.yourpackage.builders.InvoiceBuilder"/>
     </entry>
   </map>
 </property>
</bean>


Saludos.
Alejandro.

On Fri, Feb 13, 2009 at 2:06 AM, El Acuariano <acuariano@...> wrote:
> Hi,
> I've been noticed by Jira that this is already solved. I still don't
> understand how to add my builder to the director... Any help?
>
> On Tue, Feb 3, 2009 at 9:27 PM, Alejandro Scandroli
> <ascandroli@...> wrote:
>>
>> 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
>>
>>
>
>

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

   http://xircles.codehaus.org/manage_email



 « Return to Thread: Custom value and Builder