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 <[email protected]> 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

Reply via email to