You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Mandrake <ig...@gmail.com> on 2012/12/12 13:29:37 UTC

ListChoice + Ajax

Hi to all. I`m new to Apache wicket and i need your help. I wrote small
application but i cannot resolve one problem. Here is my code:

 Form form = new Form(NODE_FORM_ID);
        addOrReplace(form);

        List<Node> nodeStorage = nodeManager.getNodesStorage();
        if(!CollectionUtils.isEmpty(nodeStorage)) {
            Node defaultSelected = nodeStorage.get(0);
            this.selectedNode = defaultSelected;
            this.lastSelectedNode =  defaultSelected;
        }
        nodeTitle = new TextField<String>(NODE_TITLE_ID, new
Model(selectedNode.getTitle()), String.class);
        nodeTitle.setOutputMarkupId(true);
        form.add(nodeTitle);

        nodeText = new TextArea<String>(NODE_TEXT_ID, new
Model(selectedNode.getText()));
        nodeText.setType(String.class);
        nodeText.setOutputMarkupId(true);
        form.add(nodeText);

        nodeList = new ListChoice<Node>(NODES_LIST_ID, new
PropertyModel<Node>(this,  "selectedNode"), nodeManager.getNodesStorage());
        nodeList.add(new AjaxFormComponentUpdatingBehavior("onchange") {
            private static final long serialVersionUID =
2604279030812705608L;

            protected void onUpdate(AjaxRequestTarget target) {
                *//
                // How to get actual value of "nodeTitle" and  "nodeText" 
                //*
                onSelectionChanged();
                updateForm(target);
            }
        });
        nodeList.setOutputMarkupId(true);
        nodeList.setChoiceRenderer(new IChoiceRenderer<Node>() {
            private static final long serialVersionUID =
-4490231471856685398L;

            @Override
            public Object getDisplayValue(Node node) {
                return node.getTitle();
            }

            @Override
            public String getIdValue(Node node, int i) {
                return String.valueOf(node.getId());
            }
        });
        form.add(nodeList);

As i think, I must put to ajax request "nodeTitle" and "nodeText". But i
don`t know how to do that. Please help me!

P.S. Thanks to all responded! I hope you!



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListChoice-Ajax-tp4654732.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: ListChoice + Ajax

Posted by Mandrake <ig...@gmail.com>.
Thank you very much for helping! But with this code i can load data from
'selectedNode' to inputs elements. However i want to save data from input
elements to selected node. 



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListChoice-Ajax-tp4654732p4654748.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: ListChoice + Ajax

Posted by Sven Meier <sv...@meiers.net>.
You have to use an AjaxFormSubmitBehavior, then the textFields and the
selection of the listChoice will be pushed to the server in one go.

Sven


Mandrake wrote
> Thank you very much for helping! But with this code i can load data from
> 'selectedNode' to inputs elements. However i want to save data from input
> elements to selected node.





--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListChoice-Ajax-tp4654732p4654753.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: ListChoice + Ajax

Posted by Mandrake <ig...@gmail.com>.
Mandrakeonline
2 posts
	
Thank you very much for helping! But with this code i can load data from
'selectedNode' to inputs elements. However i want to save data from input
elements to selected node. 



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListChoice-Ajax-tp4654732p4654749.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: ListChoice + Ajax

Posted by Sven Meier <sv...@meiers.net>.
Just bind the textfields to the selectedNode, then they are always 
up-to-date.
BTW a LDM helps if #getNodesStorage() is an expensive call:

     Form form = new Form(NODE_FORM_ID);
         addOrReplace(form);

     final IModel<List<Node>> nodeStorage = new 
LoadableDetachableModel<List<Node>> {
         public List<Node> load() {
             return nodeManager.getNodesStorage();
         }
     };

     if (!nodeStorage.getObject().isEmpty()) {
             Node defaultSelected = nodeStorage.getObject().get(0);
             this.selectedNode = defaultSelected;
             this.lastSelectedNode =  defaultSelected;
     }

     form.add(new TextField<String>(NODE_TITLE_ID, new 
PropertyModel(this, "selectedNode.title")).setOutputMarkupId(true));
     form.add(new TextField<String>(NODE_TEXT_ID, new 
PropertyModel(this, "selectedNode.text")).setOutputMarkupId(true));

     nodeList = new ListChoice<Node>(NODES_LIST_ID, new 
PropertyModel<Node>(this, "selectedNode"), nodeStorage);
     nodeList.add(new AjaxFormComponentUpdatingBehavior("onchange") {
         private static final long serialVersionUID = 2604279030812705608L;

         protected void onUpdate(AjaxRequestTarget target) {
             // nothing to do here
             onSelectionChanged();
             updateForm(target);
         }
     });
     nodeList.setOutputMarkupId(true);
     nodeList.setChoiceRenderer(new IChoiceRenderer<Node>() {
         private static final long serialVersionUID = -4490231471856685398L;

         @Override
         public Object getDisplayValue(Node node) {
             return node.getTitle();
         }

         @Override
         public String getIdValue(Node node, int i) {
             return String.valueOf(node.getId());
         }
     });
     form.add(nodeList);


On 12/12/2012 01:29 PM, Mandrake wrote:
> Hi to all. I`m new to Apache wicket and i need your help. I wrote small
> application but i cannot resolve one problem. Here is my code:
>
>   Form form = new Form(NODE_FORM_ID);
>          addOrReplace(form);
>
>          List<Node> nodeStorage = nodeManager.getNodesStorage();
>          if(!CollectionUtils.isEmpty(nodeStorage)) {
>              Node defaultSelected = nodeStorage.get(0);
>              this.selectedNode = defaultSelected;
>              this.lastSelectedNode =  defaultSelected;
>          }
>          nodeTitle = new TextField<String>(NODE_TITLE_ID, new
> Model(selectedNode.getTitle()), String.class);
>          nodeTitle.setOutputMarkupId(true);
>          form.add(nodeTitle);
>
>          nodeText = new TextArea<String>(NODE_TEXT_ID, new
> Model(selectedNode.getText()));
>          nodeText.setType(String.class);
>          nodeText.setOutputMarkupId(true);
>          form.add(nodeText);
>
>          nodeList = new ListChoice<Node>(NODES_LIST_ID, new
> PropertyModel<Node>(this,  "selectedNode"), nodeManager.getNodesStorage());
>          nodeList.add(new AjaxFormComponentUpdatingBehavior("onchange") {
>              private static final long serialVersionUID =
> 2604279030812705608L;
>
>              protected void onUpdate(AjaxRequestTarget target) {
>                  *//
>                  // How to get actual value of "nodeTitle" and  "nodeText"
>                  //*
>                  onSelectionChanged();
>                  updateForm(target);
>              }
>          });
>          nodeList.setOutputMarkupId(true);
>          nodeList.setChoiceRenderer(new IChoiceRenderer<Node>() {
>              private static final long serialVersionUID =
> -4490231471856685398L;
>
>              @Override
>              public Object getDisplayValue(Node node) {
>                  return node.getTitle();
>              }
>
>              @Override
>              public String getIdValue(Node node, int i) {
>                  return String.valueOf(node.getId());
>              }
>          });
>          form.add(nodeList);
>
> As i think, I must put to ajax request "nodeTitle" and "nodeText". But i
> don`t know how to do that. Please help me!
>
> P.S. Thanks to all responded! I hope you!
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListChoice-Ajax-tp4654732.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