Re: Updating multiple PropertyModels
You don't need the wrapper. If you give PropertyModel a IModel as object it knows how to handle it. I do that all the time: Single backing IModel with lots of different IModel in front (property models, AROM, etc.) Frank On Wed, Apr 30, 2008 at 7:09 AM, Martin Makundi [EMAIL PROTECTED] wrote: I use Ajax and in an OnChange event I reload/replace some model objects and add the components holding the models into ajaxupdatetarget. I have not found another way to replace the model objects using a single point of entry. ** Martin 2008/4/29 Johan Compagner [EMAIL PROTECTED]: Why do you want to propagate the changes? Why isnt it just pull instead of push? Or do you use ajax and you have to know what components have to be rerendered? On 4/28/08, Martin Makundi [EMAIL PROTECTED] wrote: Hi! I have a situation where I have multiple propertymodels whose model-object changes as a result of an update. I need to propagate this change to all the property models. Is there an existing functionality to accomplish this? I came up with a workaround, but I would like to know if there was a proper way to deal with the situation. Here is my workaround, which smells a bit like a hack: public class WrappedPropertyModel extends PropertyModel { /** * @param model The model whose modelObject can be changed and the change will be represented by all WrappedPropetyModels sharing the same model * @param property The property of the modelObject that is wanted */ public WrappedPropertyModel(IModel model, String property) { // Strictly speaking, the IModel here could be any wrapper object super(model, object. + property); } } ** Martin - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Updating multiple PropertyModels
Hi! Please give me an example: MyData myData = new MyData(name, address); // pseudo add(new Label(name, new PropertyModel(myData, name)); add(new Label(address, new PropertyModel(myData, address)); // now I have an ajax button or something... @Override protected void onUpdate(AjaxRequestTarget target) { int stateChangeKey = (Integer) thisGadget.getModelObject(); myData = ComplexBusinessLogicService.loadNewDataAccordingToState(stateChangeKey); } Now you mean if I wrap the myData into an IModel I do not need to change anything else except the first line: MyData myData = new MyData(name, address); // pseudo IModel myDataIModel = new MyIModel(myData); and replace it in the property models? Wow. So PropertyModel will be smart enough here on its own. ** Martin 2008/4/30 Frank Bille [EMAIL PROTECTED]: You don't need the wrapper. If you give PropertyModel a IModel as object it knows how to handle it. I do that all the time: Single backing IModel with lots of different IModel in front (property models, AROM, etc.) Frank On Wed, Apr 30, 2008 at 7:09 AM, Martin Makundi [EMAIL PROTECTED] wrote: I use Ajax and in an OnChange event I reload/replace some model objects and add the components holding the models into ajaxupdatetarget. I have not found another way to replace the model objects using a single point of entry. ** Martin 2008/4/29 Johan Compagner [EMAIL PROTECTED]: Why do you want to propagate the changes? Why isnt it just pull instead of push? Or do you use ajax and you have to know what components have to be rerendered? On 4/28/08, Martin Makundi [EMAIL PROTECTED] wrote: Hi! I have a situation where I have multiple propertymodels whose model-object changes as a result of an update. I need to propagate this change to all the property models. Is there an existing functionality to accomplish this? I came up with a workaround, but I would like to know if there was a proper way to deal with the situation. Here is my workaround, which smells a bit like a hack: public class WrappedPropertyModel extends PropertyModel { /** * @param model The model whose modelObject can be changed and the change will be represented by all WrappedPropetyModels sharing the same model * @param property The property of the modelObject that is wanted */ public WrappedPropertyModel(IModel model, String property) { // Strictly speaking, the IModel here could be any wrapper object super(model, object. + property); } } ** Martin - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Updating multiple PropertyModels
Well. I do not have hierarchical models. I have just one single-level model which is used in several propertymodels. I will try if it works to wrap it. ** Martin 2008/4/30 Per Newgro [EMAIL PROTECTED]: Am Mittwoch, 30. April 2008 08:29:10 schrieb Martin Makundi: Hi! Please give me an example: MyData myData = new MyData(name, address); // pseudo add(new Label(name, new PropertyModel(myData, name)); add(new Label(address, new PropertyModel(myData, address)); // now I have an ajax button or something... @Override protected void onUpdate(AjaxRequestTarget target) { int stateChangeKey = (Integer) thisGadget.getModelObject(); myData = ComplexBusinessLogicService.loadNewDataAccordingToState(stateChangeKey); } I normally do it the following way At the highest entry point (page mostly) MyBusinessModelWithoutWicketStuff myModel = Service.createTheBusinessModel(); CompoundPropertyModel model = new CompoundPropertyModel(myModel); myPage.setModel(model); IModel pathToMySubModel = new PropertyModel(model, property1); MyPanel p1 = new MyPanel(id1, pathToMySubModel); IModel pathToMyDeepestModel = new PropertyModel(pathToMySubModel, deepestModel); MyPanel p2 = new MyPanel(id2, pathToMyDeepestModel); and so on. I imagine myself the connected property models as a path to my data. Only the highest level component has the business instance set. All others simply get the path to it. Now you mean if I wrap the myData into an IModel I do not need to change anything else except the first line: MyData myData = new MyData(name, address); // pseudo IModel myDataIModel = new MyIModel(myData); and replace it in the property models? Wow. So PropertyModel will be smart enough here on its own. Simply try it. It works great. cheers Per - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Updating multiple PropertyModels
Am Mittwoch, 30. April 2008 08:29:10 schrieb Martin Makundi: Hi! Please give me an example: MyData myData = new MyData(name, address); // pseudo add(new Label(name, new PropertyModel(myData, name)); add(new Label(address, new PropertyModel(myData, address)); // now I have an ajax button or something... @Override protected void onUpdate(AjaxRequestTarget target) { int stateChangeKey = (Integer) thisGadget.getModelObject(); myData = ComplexBusinessLogicService.loadNewDataAccordingToState(stateChangeKey); } I normally do it the following way At the highest entry point (page mostly) MyBusinessModelWithoutWicketStuff myModel = Service.createTheBusinessModel(); CompoundPropertyModel model = new CompoundPropertyModel(myModel); myPage.setModel(model); IModel pathToMySubModel = new PropertyModel(model, property1); MyPanel p1 = new MyPanel(id1, pathToMySubModel); IModel pathToMyDeepestModel = new PropertyModel(pathToMySubModel, deepestModel); MyPanel p2 = new MyPanel(id2, pathToMyDeepestModel); and so on. I imagine myself the connected property models as a path to my data. Only the highest level component has the business instance set. All others simply get the path to it. Now you mean if I wrap the myData into an IModel I do not need to change anything else except the first line: MyData myData = new MyData(name, address); // pseudo IModel myDataIModel = new MyIModel(myData); and replace it in the property models? Wow. So PropertyModel will be smart enough here on its own. Simply try it. It works great. cheers Per - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Updating multiple PropertyModels
Martin Makundi wrote: Please give me an example: Would the following work for you? It uses a combination of CompoundPropertyModel and setObjectModel. class Address { public String getStreet()... public void setStreet(String street)... public String getCity()... public void setCity(String city)... } Form form1 = new Form(form1); form1.setOutputMarkupId(true); form1.setModel(new CompoundPropertyModel(someService.getAddress())); TextField street = new TextField(street); form1.add(street); TextField city = new TextField(city); form1.add(city); AjaxButton submit = new AjaxButton(submit) { @Override protected void onSubmit(AjaxRequestTarget tgt, Form form) { Address address = (Address)form.getModelObject(); someService.updateAddress(address); form.setModelObject(someService.getAddress()); tgt.addComponent(form); }; }; form1.add(submit); add(form1); -- View this message in context: http://www.nabble.com/Updating-multiple-PropertyModels-tp16944966p16993026.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Updating multiple PropertyModels
Would the following work for you? It uses a combination of CompoundPropertyModel and setObjectModel. Address address = (Address)form.getModelObject(); someService.updateAddress(address); form.setModelObject(someService.getAddress()); tgt.addComponent(form); No. I do not have a simple form. I have multiple listchoicess and hierarchical listviews. ** Martin - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Updating multiple PropertyModels
I use Ajax and in an OnChange event I reload/replace some model objects and add the components holding the models into ajaxupdatetarget. I have not found another way to replace the model objects using a single point of entry. ** Martin 2008/4/29 Johan Compagner [EMAIL PROTECTED]: Why do you want to propagate the changes? Why isnt it just pull instead of push? Or do you use ajax and you have to know what components have to be rerendered? On 4/28/08, Martin Makundi [EMAIL PROTECTED] wrote: Hi! I have a situation where I have multiple propertymodels whose model-object changes as a result of an update. I need to propagate this change to all the property models. Is there an existing functionality to accomplish this? I came up with a workaround, but I would like to know if there was a proper way to deal with the situation. Here is my workaround, which smells a bit like a hack: public class WrappedPropertyModel extends PropertyModel { /** * @param model The model whose modelObject can be changed and the change will be represented by all WrappedPropetyModels sharing the same model * @param property The property of the modelObject that is wanted */ public WrappedPropertyModel(IModel model, String property) { // Strictly speaking, the IModel here could be any wrapper object super(model, object. + property); } } ** Martin - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]