hudi
hudi

Reputation: 16525

How to get value of model in wicket behavior

in my form I have input text and then dataView:

private class RegistrationForm extends Form<Table> {

    private static final long serialVersionUID = 1L;

    public RegistrationForm(final Table table) {
        super("registrationForm", new CompoundPropertyModel<Table>(table));
        setOutputMarkupId(true);
        final TextField<String> text = new TextField<String>("name");
        add(text);
        DataView<Player> dataView = new DataView<Player>("rows", playerDataProvider) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void populateItem(final Item<Player> listItem) {
...

on listItem I add ajaxEventBehavior when I double Click on row:

                listItem.add(new AjaxEventBehavior("ondblclick") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    protected void onEvent(final AjaxRequestTarget target) {
                            System.out.println(table.getName());

                     }
                });

Problem is when I double click on table it print null not the value which I have in input TextField. Why ?

I try to update model:

                            text.updateModel();

or get value from text:

                            System.out.println(table.getName() + "bbbbbbbbbbbbbbbbb" + text.getInput() + "vv"
                                    + text.getValue() + "ff");

but with no success.

in form I have also submit button and when I press it every think works. I have problems just with double click

Upvotes: 1

Views: 2343

Answers (1)

Carl-Eric Menzel
Carl-Eric Menzel

Reputation: 1266

AjaxEventBehavior itself does not submit the form, so you're not getting the text field value. You can use one of the following subclasses instead:

  • AjaxFormComponentUpdatingBehavior will submit only the one FormComponent it is attached to. It needs to be attached to a FormComponent, so you'll have to use the following if you want to attach it to the entire ListItem:
  • AjaxFormSubmitBehavior will submit the entire form. This is probably what you need here.

All these behaviors are included in Wicket and their Javadoc is right there with the source code. For the Ajax stuff, check subclasses of AbstractAjaxBehavior, in particular the subclasses of AjaxEventBehavior.

Upvotes: 6

Related Questions