You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by ganea iulia <su...@gmail.com> on 2016/12/16 15:24:56 UTC

Form with backing loadabledetachable model

Hello,
I have a list of items in a Refreshing View.
When I click on a link inside the Refreshing View, a form in the same page
should get populated with the values from the line.

I have managed to do this, by having inside the Form a
LoadableDetacheableModel and then use this model as backing model for the
components in the form.

However, I have also a drop down inside the form, but when changing the
value, the LoadableDetacheableModel does not get updated with the new
value.

Or if using getModelObject(), all values are null, because, the backing
model of the form is null.

Could you please advise?

Thank you

Re: Form with backing loadabledetachable model

Posted by Sven Meier <sv...@meiers.net>.
Hi,

you should brush up your model usage:

     final MyBean tst = poItemsListModel.getObject();

Your pulling the model object from the model *once* only. The reference 
'tst' never gets updated, when the model changes.

I've attached an alternative solution below. I'd recommend not changing 
models after components are constructed. It's much easier to change 
model objects only.

Have fun
Sven


// edit link
AjaxLink<MyBean> linkEditItem = new AjaxLink<MyBean>("linkEditForm", model)
{
     @Override
     public void onClick(AjaxRequestTarget target) {
         feedbackPanel.getFeedbackMessages().clear();
         editForm.clearInput();

         // I'd advice against changing models - better change the model 
object
         editForm.setModelObject(item.getModelObject());

         target.add(editForm);
         target.add(feedbackPanel);
     }
};

class EditForm extends Form<MyBean> {

     public EditForm(String id, IModel<MyBean> model) {
         super(id, model);

         // Edit ITEMS
         final WebMarkupContainer editContainer = new 
WebMarkupContainer("editContainer");
         editContainer.setOutputMarkupId(true);
         add(editContainer);

         // unrepairable
         DropDownChoice<String> unrepairable = new 
DropDownChoice<String>("unrepairable", lstSN, renderer) {
             @Override
             public boolean isEnabled() {
                 final MyBean tst = poItemsListModel.getObject();

                 return (tst.getId() == null || (tst.getIrreparableSal() 
!= null &&
                     !tst.getIrreparableSal().equals("S")));
             }
         };

         unrepairable.setModel(new PropertyModel<String>(getModel(), 
"irreparableSal"));
         unrepairable.setOutputMarkupId(true);
         editContainer.add(unrepairable);
         unrepairable.add(new AjaxFormComponentUpdatingBehavior("change") {
             @Override
             protected void onUpdate(AjaxRequestTarget target) {
                 target.add(unrepairable);
             }
         });



On 19.12.2016 09:28, ganea iulia wrote:
> Hello,
>
> =Here is the RefreshingView link item. When clicking on this link, the form
> should be filled with the values of this RefreshingView line.
> When click on the link, I set the property itemmodel with the line model.
> The itemmodel is then used by the LoadableDetacheableModel, to get the
> values for the form.
>
>
> // edit link
> AjaxLink<MyBean> linkEditItem = new AjaxLink<MyBean>("linkEditForm", model)
> {
> private static final long serialVersionUID = 15L;
>
> @Override
> public void onClick(AjaxRequestTarget target) {
> feedbackPanel.getFeedbackMessages().clear();
> editForm.clearInput();
> editForm.setItemmodel(new Model<MyBean>(item.getModelObject()));
> target.add(editForm);
> target.add(feedbackPanel);
> }
> };
>
> =Here is the form:
>
> class EditForm extends Form<MyBean> {
>
> /**
> * Form where you can edit the items from the list
> */
> private static final long serialVersionUID = 1L;
> private IModel<MyBean> itemmodel;
>
>
> public void setItemmodel(IModel<MyBean> itemmodel) {
> this.itemmodel = itemmodel;
> }
>
> public EditForm(String id, IModel<MyBean> model) {
> super(id, model);
>
> this.itemmodel = model;
> final LoadableDetachableModel<MyBean> poItemsListModel = new
> LoadableDetachableModel<MyBean>() {
>
> private static final long serialVersionUID = 0L;
>
> @Override
> protected MyBean load() {
> return itemmodel.getObject();
> }
>
> };
> // Edit ITEMS
> final WebMarkupContainer editContainer = new
> WebMarkupContainer("editContainer");
> editContainer.setOutputMarkupId(true);
> add(editContainer);
> final MyBean tst = poItemsListModel.getObject();
> // unrepairable
> DropDownChoice<String> unrepairable = new
> DropDownChoice<String>("unrepairable", lstSN, renderer) {
>
> private static final long serialVersionUID = 1L;
>
> *@Override*
> * public boolean isEnabled() {*
> * return (tst.getId() == null || (tst.getIrreparableSal() != null &&
> !tst.getIrreparableSal().equals("S")));*
> * }*
> };
>
> unrepairable.setModel(new PropertyModel<String>(poItemsListModel,
> "irreparableSal"));
> unrepairable.setOutputMarkupId(true);
> editContainer.add(unrepairable);
> unrepairable.add(new AjaxFormComponentUpdatingBehavior("change") {
>
> private static final long serialVersionUID = 1L;
>
> @Override
> protected void onUpdate(AjaxRequestTarget target) {
> target.add(unrepairable);
> }
> });
>
> In this piece of code(also in bold above), I cannot ever get the actual
> values of my LoadableDetacheableModel; they are always null, they never get
> updated with the values of the line.
>
> *@Override*
> *public boolean isEnabled() {*
> * return (tst.getId() == null || (tst.getIrreparableSal() != null &&
> !tst.getIrreparableSal().equals("S")));*
> *}*
>
>
> On Fri, Dec 16, 2016 at 9:52 PM, Sven Meier <sv...@meiers.net> wrote:
>
>> Hi,
>>
>>> Or if using getModelObject(), all values are null, because, the backing
>>> model of the form is null.
>> how does your LDM load its model object?
>>
>> Show us some code or better create a quickstart so someone can take a look
>> at it.
>>
>> Sven
>>
>>
>>
>> On 16.12.2016 16:24, ganea iulia wrote:
>>
>>> Hello,
>>> I have a list of items in a Refreshing View.
>>> When I click on a link inside the Refreshing View, a form in the same page
>>> should get populated with the values from the line.
>>>
>>> I have managed to do this, by having inside the Form a
>>> LoadableDetacheableModel and then use this model as backing model for the
>>> components in the form.
>>>
>>> However, I have also a drop down inside the form, but when changing the
>>> value, the LoadableDetacheableModel does not get updated with the new
>>> value.
>>>
>>> Or if using getModelObject(), all values are null, because, the backing
>>> model of the form is null.
>>>
>>> Could you please advise?
>>>
>>> Thank you
>>>
>>>
>> ---------------------------------------------------------------------
>> 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


Re: Form with backing loadabledetachable model

Posted by ganea iulia <su...@gmail.com>.
Hello,

=Here is the RefreshingView link item. When clicking on this link, the form
should be filled with the values of this RefreshingView line.
When click on the link, I set the property itemmodel with the line model.
The itemmodel is then used by the LoadableDetacheableModel, to get the
values for the form.


// edit link
AjaxLink<MyBean> linkEditItem = new AjaxLink<MyBean>("linkEditForm", model)
{
private static final long serialVersionUID = 15L;

@Override
public void onClick(AjaxRequestTarget target) {
feedbackPanel.getFeedbackMessages().clear();
editForm.clearInput();
editForm.setItemmodel(new Model<MyBean>(item.getModelObject()));
target.add(editForm);
target.add(feedbackPanel);
}
};

=Here is the form:

class EditForm extends Form<MyBean> {

/**
* Form where you can edit the items from the list
*/
private static final long serialVersionUID = 1L;
private IModel<MyBean> itemmodel;


public void setItemmodel(IModel<MyBean> itemmodel) {
this.itemmodel = itemmodel;
}

public EditForm(String id, IModel<MyBean> model) {
super(id, model);

this.itemmodel = model;
final LoadableDetachableModel<MyBean> poItemsListModel = new
LoadableDetachableModel<MyBean>() {

private static final long serialVersionUID = 0L;

@Override
protected MyBean load() {
return itemmodel.getObject();
}

};
// Edit ITEMS
final WebMarkupContainer editContainer = new
WebMarkupContainer("editContainer");
editContainer.setOutputMarkupId(true);
add(editContainer);
final MyBean tst = poItemsListModel.getObject();
// unrepairable
DropDownChoice<String> unrepairable = new
DropDownChoice<String>("unrepairable", lstSN, renderer) {

private static final long serialVersionUID = 1L;

*@Override*
* public boolean isEnabled() {*
* return (tst.getId() == null || (tst.getIrreparableSal() != null &&
!tst.getIrreparableSal().equals("S")));*
* }*
};

unrepairable.setModel(new PropertyModel<String>(poItemsListModel,
"irreparableSal"));
unrepairable.setOutputMarkupId(true);
editContainer.add(unrepairable);
unrepairable.add(new AjaxFormComponentUpdatingBehavior("change") {

private static final long serialVersionUID = 1L;

@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(unrepairable);
}
});

In this piece of code(also in bold above), I cannot ever get the actual
values of my LoadableDetacheableModel; they are always null, they never get
updated with the values of the line.

*@Override*
*public boolean isEnabled() {*
* return (tst.getId() == null || (tst.getIrreparableSal() != null &&
!tst.getIrreparableSal().equals("S")));*
*}*


On Fri, Dec 16, 2016 at 9:52 PM, Sven Meier <sv...@meiers.net> wrote:

> Hi,
>
> >Or if using getModelObject(), all values are null, because, the backing
> >model of the form is null.
>
> how does your LDM load its model object?
>
> Show us some code or better create a quickstart so someone can take a look
> at it.
>
> Sven
>
>
>
> On 16.12.2016 16:24, ganea iulia wrote:
>
>> Hello,
>> I have a list of items in a Refreshing View.
>> When I click on a link inside the Refreshing View, a form in the same page
>> should get populated with the values from the line.
>>
>> I have managed to do this, by having inside the Form a
>> LoadableDetacheableModel and then use this model as backing model for the
>> components in the form.
>>
>> However, I have also a drop down inside the form, but when changing the
>> value, the LoadableDetacheableModel does not get updated with the new
>> value.
>>
>> Or if using getModelObject(), all values are null, because, the backing
>> model of the form is null.
>>
>> Could you please advise?
>>
>> Thank you
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Form with backing loadabledetachable model

Posted by Sven Meier <sv...@meiers.net>.
Hi,

 >Or if using getModelObject(), all values are null, because, the backing
 >model of the form is null.

how does your LDM load its model object?

Show us some code or better create a quickstart so someone can take a 
look at it.

Sven


On 16.12.2016 16:24, ganea iulia wrote:
> Hello,
> I have a list of items in a Refreshing View.
> When I click on a link inside the Refreshing View, a form in the same page
> should get populated with the values from the line.
>
> I have managed to do this, by having inside the Form a
> LoadableDetacheableModel and then use this model as backing model for the
> components in the form.
>
> However, I have also a drop down inside the form, but when changing the
> value, the LoadableDetacheableModel does not get updated with the new
> value.
>
> Or if using getModelObject(), all values are null, because, the backing
> model of the form is null.
>
> Could you please advise?
>
> Thank you
>


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