Model crModel = new Model(){
     getObject(){
        return contextData.getDTO(p.getDeptId());
      }
     setObject(Object o){
            p.setDeptId( ((DTO) o).getId());
     }
};

On Wed, Nov 4, 2009 at 2:32 PM, Xavier López <xavil...@gmail.com> wrote:

> Hi Sven, Pedro,
>
> Thanks both for your quick reply.
>
> Ideally you would just set a Department instance into your Person objects
>
>
> the best way is you have your depid property of type Department
>
> This was the first approach to take into account, but the idea was
> discarded
> in benefit of SimpleElementDTO, in order to provide only the necessary
> information to Wicket Models, with the intention of not wasting any memory
> on PageMaps due to Department object serializations... Also, this
> SimpleElementDTO would be reusable throughout the whole application when
> it's about Radio and DropDown Choices...
>
> write some specialized render
> >
> This kinda 'dirty-fix' idea was already crawling in my mind, trying to come
> out someway. Thanks for providing a concrete implementation.
>
> So, in the end I'm trying to provide a custom model. Something like:
>
> Java
> ------------------------
> final Person p;
>
> Model crModel = new Model(){
>      getObject(){
>         return p.getDeptId();
>       }
>      setObject(Object o){
>             // o is String!
>             p.setDeptId( (String) o);
>       }
> };
> ChoiceRenderer cr = new ChoiceRenderer("deptId", choices, new
> ChoiceRenderer("id", "description"));
> cr.setModel(crModel);
>
> But i'm stucking into the same error, as this Model it's kind like a
> PropertyModel which would be assumed by having the former
> CompoundPropertyModel...
>
> Any thoughts ? Maybe rendering labels independently ?
>
> It's strange nobody has bumped into this situation before.. Maybe it's
> because i'm still thinking like I was using Struts...
>
> Thanks to both again,
> Cheers !
>
>
> 2009/11/4 Pedro Santos <pedros...@gmail.com>
>
> > Hi Sven, he stell can write some specialized render... but I think the
> best
> > way is you have your depid property of type Department. Than all this
> > thread
> > would not have started :)
> >
> > class YourCustomRender
> >    {
> >        @Override
> >        public String getIdValue(Object object, int index)
> >        {
> >            if (object instanceof DTO)
> >            {
> >                return ((DTO)object).getDeptId()
> >            }
> >            else
> >            {
> >                return (String)object;//already is the depid string
> >            }
> >        }
> >
> >        @Override
> >        public Object getDisplayValue(Object object)
> >        {
> >            if (object instanceof DTO)
> >            {
> >                return ((DTO)object).getDescription();
> >            }
> >            else
> >            {
> >                return contextData.getDTOBasedOnDepid(object);
> >             }
> >        }
> >    }
> >
> > On Wed, Nov 4, 2009 at 1:29 PM, Xavier López <xavil...@gmail.com> wrote:
> >
> > > Hi,
> > >
> > > I have a question regarding the use of RadioChoice and ChoiceRenderer's
> > in
> > > conjunction with CompoundPropertyModel. I'm new to Wicket (but already
> a
> > > convinced user ;) ), so maybe my approach on this one is not at all as
> it
> > > should be... Any comments are welcome !
> > >
> > > I'll get into details. Let's say I have a class in my domain model
> named
> > > Person. This entity has a property named 'deptId' of type String. The
> > > Person
> > > entity is the backing for a CompundPropertyModel applied to the whole
> > form.
> > > The 'deptId' field is inputted by the user, let's say, by means of a
> > > RadioChoice (I guess it makes no difference from a DropDownChoice
> taking
> > > into account the point of the question). The choice list for the
> > > RadioChoice
> > > component is a List made up of DTO objects with properties "id" and
> > > "description". To ensure proper rendering of labels, I use a suitable
> > > ChoiceRenderer.
> > >
> > > Now, problems come when the 'deptId' property has a value in the Person
> > > entity used in the CompoundPropertyModel. I get an error saying that
> > class
> > > String does not have any property called 'id' (I suppose this error
> comes
> > > from having a ModelObject of type String and also having a
> ChoiceRenderer
> > > refering to 'id' property).
> > >
> > > I'll provide some sample code:
> > >
> > > markup
> > > -------------
> > > ...
> > > <form wicket:id="form">
> > >    ...
> > >    <span valign="top" wicket:id="deptId"></span>
> > >    ...
> > > </form>
> > > ...
> > >
> > > Java
> > > -------------
> > >
> > > ...
> > > List<SimpleElementDTO> choices = contextData.getChoices();
> > > Person p = new Person(...);
> > > Form f = new Form("form"){...};
> > > f.setModel(new CompoundPropertyModel(p));
> > > ChoiceRenderer cr = new ChoiceRenderer("deptId", choices, new
> > > ChoiceRenderer("id", "description"));
> > > f.add(cr);
> > > ...
> > >
> > >
> > > I suppose the 'normal' way of doing things would be providing a custom
> > > Model
> > > to 'cr', but I'd like to know if there is a possibility to achieve this
> > > point still using CompoundPropertyModel...
> > >
> > > The stack trace I get is the following:
> > >
> > > WicketMessage: No get method defined for class: class java.lang.String
> > > expression: id
> > > Root cause:
> > > org.apache.wicket.WicketRuntimeException: No get method defined for
> > class:
> > > class java.lang.String expression: id
> > > at
> > >
> > >
> >
> org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:440)
> > > at
> > >
> > >
> >
> org.apache.wicket.util.lang.PropertyResolver.getObjectAndGetSetter(PropertyResolver.java:282)
> > > at
> > >
> > >
> >
> org.apache.wicket.util.lang.PropertyResolver.getValue(PropertyResolver.java:91)
> > > at
> > >
> > >
> >
> org.apache.wicket.markup.html.form.ChoiceRenderer.getIdValue(ChoiceRenderer.java:140)
> > > at
> > >
> > >
> >
> org.apache.wicket.markup.html.form.AbstractSingleSelectChoice.getModelValue(AbstractSingleSelectChoice.java:144)
> > > at
> > >
> > >
> >
> org.apache.wicket.markup.html.form.FormComponent.getValue(FormComponent.java:797)
> > > at
> > >
> > >
> >
> org.apache.wicket.markup.html.form.RadioChoice.onComponentTagBody(RadioChoice.java:407)
> > > at org.apache.wicket.Component.renderComponent(Component.java:2480)
> > > at
> org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1411)
> > > at org.apache.wicket.Component.render(Component.java:2317)
> > > at
> > org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1297)
> > > ...
> > >
> >
> >
> >
> > --
> > Pedro Henrique Oliveira dos Santos
> >
>
>
>
> --
> "To err is human; to make real mess, you need a computer."
>



-- 
Pedro Henrique Oliveira dos Santos

Reply via email to