You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sebastian80 <s....@gmail.com> on 2011/11/12 11:46:51 UTC

Model isn't updated on AJAX submit link invocation

Hi there,

I'm trying to implement an AJAXfied Wicket list view. On my research I
stumbled upon the code on
http://www.oktech.hu/kb/adding-and-removing-rows-wicket-listview-via-ajax
and modified it a bit.

The model is not updated properly. So whenever a value is entered in a text
field, it is forgotten if the AJAX submit link is invoked (the text field is
empty again). Why does this happen? I don't see any issue with this code.
Wicket version is 1.5.2.

Here is the Java code:

// Initialization of form
...

// List all rows
ArrayList<String> rows = new ArrayList<String>(2);
rows.add(new String());
rows.add(new String());

final ListView<String> lv = new ListView<String>("rows", rows) {
    @Override
    protected void populateItem(ListItem<String> item) {
        int index = item.getIndex() + 1;
        item.add(new Label("index", index + "."));

        TextField<String> text = new TextField<String>("text",
item.getModel());
        item.add(text);
    }
};
rowPanel.add(lv);

    AjaxSubmitLink addLink = new AjaxSubmitLink("addRow", form) {

    @Override
    protected void onError(AjaxRequestTarget target, Form<?> form) {
        if (target != null) target.add(rowPanel);       
    }

    @Override
    protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
        lv.getModelObject().add(new String());
        if (target != null) target.add(rowPanel);
    }
};
addLink.setDefaultFormProcessing(false);
rowPanel.add(addLink);
...

And the associated mark up:
<div wicket:id="rowPanel">
    
        1.
        <input type="text" wicket:id="text"/>
    
     # Add row 
</div>

Has someone any idea on this issue? I'm completely stuck on this issue.
Thanks in advance.

Best regards,
Sebastian 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-isn-t-updated-on-AJAX-submit-link-invocation-tp4034095p4034095.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Model isn't updated on AJAX submit link invocation

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Here is another article about adding items in a repeater with Ajax:
http://wicketinaction.com/2008/10/repainting-only-newly-created-repeater-items-via-ajax/

On Sat, Nov 12, 2011 at 3:37 PM, Станислав Савульчик
<sa...@ess54.ru> wrote:
> Hi,
>
> The form components aren't updated because form processing for AjaxSubmitLink is set to false.
> See the javadoc for AjaxSubmitLink#setDefaultFormProcessing.
>
> BTW, when using ListView for rendering form components consider reading WARNING section in javadoc for ListView class.
>
> ----- Исходное сообщение -----
> От: "Sebastian80" <s....@gmail.com>
> Кому: users@wicket.apache.org
> Отправленные: Суббота, 12 Ноябрь 2011 г 17:46:51
> Тема: Model isn't updated on AJAX submit link invocation
>
> Hi there,
>
> I'm trying to implement an AJAXfied Wicket list view. On my research I
> stumbled upon the code on
> http://www.oktech.hu/kb/adding-and-removing-rows-wicket-listview-via-ajax
> and modified it a bit.
>
> The model is not updated properly. So whenever a value is entered in a text
> field, it is forgotten if the AJAX submit link is invoked (the text field is
> empty again). Why does this happen? I don't see any issue with this code.
> Wicket version is 1.5.2.
>
> Here is the Java code:
>
> // Initialization of form
> ...
>
> // List all rows
> ArrayList<String> rows = new ArrayList<String>(2);
> rows.add(new String());
> rows.add(new String());
>
> final ListView<String> lv = new ListView<String>("rows", rows) {
>    @Override
>    protected void populateItem(ListItem<String> item) {
>        int index = item.getIndex() + 1;
>        item.add(new Label("index", index + "."));
>
>        TextField<String> text = new TextField<String>("text",
> item.getModel());
>        item.add(text);
>    }
> };
> rowPanel.add(lv);
>
>    AjaxSubmitLink addLink = new AjaxSubmitLink("addRow", form) {
>
>    @Override
>    protected void onError(AjaxRequestTarget target, Form<?> form) {
>        if (target != null) target.add(rowPanel);
>    }
>
>    @Override
>    protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
>        lv.getModelObject().add(new String());
>        if (target != null) target.add(rowPanel);
>    }
> };
> addLink.setDefaultFormProcessing(false);
> rowPanel.add(addLink);
> ...
>
> And the associated mark up:
> <div wicket:id="rowPanel">
>
>        1.
>        <input type="text" wicket:id="text"/>
>
>     # Add row
> </div>
>
> Has someone any idea on this issue? I'm completely stuck on this issue.
> Thanks in advance.
>
> Best regards,
> Sebastian
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-isn-t-updated-on-AJAX-submit-link-invocation-tp4034095p4034095.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Model isn't updated on AJAX submit link invocation

Posted by Станислав Савульчик <sa...@ess54.ru>.
Hi,

The form components aren't updated because form processing for AjaxSubmitLink is set to false. 
See the javadoc for AjaxSubmitLink#setDefaultFormProcessing.

BTW, when using ListView for rendering form components consider reading WARNING section in javadoc for ListView class.

----- Исходное сообщение -----
От: "Sebastian80" <s....@gmail.com>
Кому: users@wicket.apache.org
Отправленные: Суббота, 12 Ноябрь 2011 г 17:46:51
Тема: Model isn't updated on AJAX submit link invocation

Hi there,

I'm trying to implement an AJAXfied Wicket list view. On my research I
stumbled upon the code on
http://www.oktech.hu/kb/adding-and-removing-rows-wicket-listview-via-ajax
and modified it a bit.

The model is not updated properly. So whenever a value is entered in a text
field, it is forgotten if the AJAX submit link is invoked (the text field is
empty again). Why does this happen? I don't see any issue with this code.
Wicket version is 1.5.2.

Here is the Java code:

// Initialization of form
...

// List all rows
ArrayList<String> rows = new ArrayList<String>(2);
rows.add(new String());
rows.add(new String());

final ListView<String> lv = new ListView<String>("rows", rows) {
    @Override
    protected void populateItem(ListItem<String> item) {
        int index = item.getIndex() + 1;
        item.add(new Label("index", index + "."));

        TextField<String> text = new TextField<String>("text",
item.getModel());
        item.add(text);
    }
};
rowPanel.add(lv);

    AjaxSubmitLink addLink = new AjaxSubmitLink("addRow", form) {

    @Override
    protected void onError(AjaxRequestTarget target, Form<?> form) {
        if (target != null) target.add(rowPanel);       
    }

    @Override
    protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
        lv.getModelObject().add(new String());
        if (target != null) target.add(rowPanel);
    }
};
addLink.setDefaultFormProcessing(false);
rowPanel.add(addLink);
...

And the associated mark up:
<div wicket:id="rowPanel">
    
        1.
        <input type="text" wicket:id="text"/>
    
     # Add row 
</div>

Has someone any idea on this issue? I'm completely stuck on this issue.
Thanks in advance.

Best regards,
Sebastian 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-isn-t-updated-on-AJAX-submit-link-invocation-tp4034095p4034095.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org