Domanda

I have a wicket page with a form to edit an entity that has a many2many relation with another entity.

@Entity...
class Period {
    ...
    @Column(length = 100)
    private String description;

    @ManyToMany()
    private List<Action> actions = new ArrayList<Action>;
    ...
}

@Entity...
class Action {
    ...
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "join", joinColumns = @JoinColumn(name = "actionId"),
        inverseJoinColumns = @JoinColumn(name = "periodId"))
    private Set<Period> periods = new HashSet<Period>();
    ...
}

class FormPage {
    public FormPage(Period period) {
        CompoundPropertyModel<Period> props = new CompoundPropertyModel<Period>(period);
        Form<Period> form = new Form<Period>("id", props);
        form.add(new TextField<String>("description"));

        ???

    }
}

How do I add an 'Action' to my 'Period'? The old jsp page showed all available Action objects in the form with label and checkbox. I would like to keep the checkboxes so the look of the page doesn't change from the old jsp page. The only thing I can think of is create a hashtable the the id's of the actions available and a boolean indicating if it should be added or removed. Does anyone know a nicer way or a good example of an implementation?

È stato utile?

Soluzione 2

Found the right component to use. svenmeier pushed me vaguely in the right direction but this should be done at the question marks:

List<Action> available = dao.getAllActions();
form.add(new CheckBoxMultipleChoice<Action>(actions, available));

To properly render the string I added a ChoiceRender to the CheckBoxMultipleChoice:

new ChoiceRenderer<Action>() {
    @Override
    public Object getDisplayValue(Action object) {
        return object.getDisplayName(); //return any string describing the object
    }
}

Altri suggerimenti

Use a hierarchy of CheckGroup, ListView and Check components. See FormInput from wicket-examples for inspiration.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top