isis-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Haywood <...@haywood-associates.co.uk>
Subject Re: Custom Value Types (VALUE OBJECTS) and the annotation @Value
Date Wed, 18 Sep 2013 12:55:10 GMT
Hi Luis,
welcome to the Isis mailing list.

But my apols to you and Ezequiel, I somehow dropped the ball and missed
this question.

To answer some of your question: to get the ContactVO to persist - as you
have done - it is sufficient only to make it serializable.  However, if you
want it to be stored as something other than a blob, you'll need to use the
JDO APIs (eg as is done for Joda types).

Your issue, though, is on the UI side.  And, unfortunately, right now Isis
doesn't provide an out-of-the-box capability to render composite value
objects such as you have defined here.  It most certainly ought to do so,
and indeed we have a ticket for something very similar... [1] it just isn't
implemented, I'm afraid.

The EncoderDecoder stuff won't help... that is used by some of the other
object stores (eg XML, NoSQL).  But it's irrelevant for Wicket/JDO.

The main issue is that the Wicket viewer doesn't "look inside" the
structure of your ContactVO in order to build up a suitable UI.  For
example, the ContactVO is basically 3 string properties, and you would
presumably want 3 fields.  It's just not smart enough to do that.

I can offer a possible workaround for you, if you want, which *might* work.
 The Wicket viewer *is* extensible, and so you could define and register
your own ContactVOComponentFactory and have it build up a custom
ContactVOComponent (a panel) for rendering the parts of the contact as
individual fields.

Have a look at ComponentFactoryRegistryDefault and how some of the other
ComponentFactorys work - it's basically the chain of responsibility
pattern.

Or... alternatively you might want to generalize this, in other words
implement [1].  Note that [1] uses the AggregatedFacet as the indicator on
the referenced object that it should be displayed "inline".  If this
reference is mapped using JDO's @Embedded, it would also save you the
hassle of doing extra JDO datatype mappings.

HTH, come back to me if none of the above makes sense...

Best
Dan


[1] https://issues.apache.org/jira/browse/ISIS-348







On 18 September 2013 13:26, Luis Parada <luisparadawagner@gmail.com> wrote:

> Hi, I´m working on this with Ezequiel and we could persist the Contact VO.
> The problem is that we can not show the object in the viewer because the
> object is serialized. We found
> the public interface EncoderDecoder<T> {} wich implements this method: T
> fromEncodedString(String encodedString); so we appreciate any help
> explaining us how to use it.
>
> At this moment we have overrided the methods: protected String
> doEncode(final Object object) and protected Contact doRestore(final String
> data) of ContactoValueSemanticsProvider but is not working yet.
>
> protected String doEncode(final Object object) {
> final Contacto contacto = (Contacto) object;
> final String valor = String.valueOf(contacto.getDomicilio() + "-" +
> contacto.getEmail() + "-" + contacto.getTelefono());
> return valor;
> }
>
> protected Contacto doRestore(final String data) {
> final String[] partes = data.split("-");
> final String domicilio = partes[0];
> final String correo = partes[1];
> final String telefono = partes[2];
> return new Contacto(domicilio, correo, telefono);
> }
> Thank´s.
>
>
> 2013/9/12 Ezequiel Celiz <elceliz@gmail.com>
>
> > Hi community
> >
> > I'm trying to implement the annotation @Value in my application to use
> the
> > "Value Objects" as defined in the concept of DDD .
> >
> > I had no success : How I can set my class as a genuine Custom Value Type?
> > so that it can be used in the entities that require it.
> >
> > I want to create the classic VO : "Contact" which consists of the
> following
> > properties ( in my case) :
> >
> > Address, Telephone and Email.
> >
> >     @Value ( semanticsProviderName = "
> >  ContactValueSemanticsProvider.class " )
> >     public class Contact  {
> >
> >     / *
> >     / Need to the builder?
> >     /
> >     / Public Contact ( String a, String t , String e) {
> >     / This.address = a;
> >     / This.telephone = t;
> >     / This.email = e ;
> >     / }
> >     /
> >     / *
> >
> >     private String address ;
> >
> >     public String getAddress ( ) {
> >         return address ;
> >     }
> >
> >     public void setAddress (String address) {
> >         this.address = address ;
> >     }
> >
> >     private String telephone ;
> >
> >     getTelephone public String ( ) {
> >         return telephone ;
> >     }
> >
> >     public void setTelephone (String telephone) {
> >         this.telephone = telephone ;
> >     }
> >
> >     private String email ;
> >
> >     getEmail public String ( ) {
> >         return email ;
> >     }
> >
> >     public void setEmail (String email ) {
> >         this.email = email ;
> >     }
> >
> >  }
> >
> > where ContactValueSemanticsProvider.class :
> > public final class ContactValueSemanticsProvider
> > extends AbstractValueSemanticsProvider <Conctact> {}
> >
> > Then I wonder if the entity would have to have an attribute :
> >
> >     private Contact contact ;
> >
> >     public GetContact ( ) {
> >         return contact ;
> >     }
> >
> > Finally in the service when I creating the entity object :
> >
> >    SomeEntity public newEntity (
> >             @ Optional
> >             @ Named ( " Address" ) String address,
> >             @ Optional
> >             @ Named ( " Telephone" ) String telephone ,
> >             @ Optional
> >             @ Named ( " email " ) String email
> >             ) {
> >
> >    final Contact contact
> >
> >             / / The correct way to instantiate is THROUGH
> > newTransientInstance ( Contact.class ) ?
> >
> >             pourContacter (contact) ;
> >
> >  @ Hidden
> >  SomeEntity public pourContacter ( ) (
> >             Final Contact Contact
> >         ) {
> >         SomeEntity end someEntity = newTransientInstance (
> SomeEntity.class
> > ) ;
> >         someEntitity.setContact (contact) ;
> >         persistIfNotAlready ( someEntity ) ;
> >
> >         someEntity return ;
> >     }
> >
> > It is the right way? or the way to work with the Value Object in ISIS is
> > another?
> >
> > I welcome your suggestions
> > Thank you very much as always for your attention
> > Cheers !
> > Ezequiel
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message