简体   繁体   中英

The wicket Panel doesn't get refresh on button submit

I need to refresh the panel (it has been declared as panel in the below code) after I add a new group. The ItemSelectionComponent component is a different Panel that contains the added groups of a particular person. What I need to do is once I add a new group that particular panel (the ItemSelectionComponent panel with the wicket id "panel" ) should be refreshed and the newly added group should get displayed.

I currently use
target.addComponent(panel);
to refresh, but it doesn't seems to be working :(

Can someone tell me whats wrong?
thanks!

Your avaiableGroups should be a LoadableDetachableModel that contains your list of GroupSelectionModels. When you use the AjaxSubmitLink get List from the LoadableDetachableModel and add to it.

LoadableDetachableModel<List<GroupSelectionModel>> LDM = new LoadableDetachableModel<List<GroupSelectionModel>>() {

     private static final long serialVersionUID = 1L;

     @Override
     protected String load() {                          
           return ServiceLocator.getInstance().find(GroupService.class).getAllGroups();;
     }
};


AjaxSubmitLink addBtn = new AjaxSubmitLink("addBtn") {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> f) {

            List<Group> currentGroups = ServiceLocator.getInstance().find(GroupService.class).getAllGroups();
            Group group = new Group();
            group.setGroupType(Group.GroupType.EMAIL);
            group.setMerchant(merchant);
            group.setGroupName(form.getModelObject().getGroupName());


            ServiceLocator.getInstance().find(GroupService.class).saveGroup(group);
            GroupSelectionModel newGroup = new GroupSelectionModel();
            newGroup.setGroup(group);
            newGroup.setGroupSelected(true);
            LDM.getObject().add(newGroup);
    target.addComponent(panel);
        }
    };

Then pass LDM as a param to ItemSelectionComponent instead of avaiableGroups. Use LDM in ItemSelectionComponent like you did avaiableGroups.

 public class ItemSelectionComponent extends Panel{
private static final long serialVersionUID = 6670144847L;
private LoadableDetachableModel<List<GroupSelectionModel>> model;

public ItemSelectionComponent(String id,LoadableDetachableModel<List<GroupSelectionModel>> model){
    super(id);
    this.model = model;
    init();

}

private void init(){
    WebMarkupContainer groupSelectionContainer = new WebMarkupContainer("groupSelectionContainer");
    RepeatingView repeater = new RepeatingView("groupList");
    WebMarkupContainer groupList;

    for(final GroupSelectionModel m : model.getObject()){
        groupList = new WebMarkupContainer(repeater.newChildId());
        WebMarkupContainer groupNameContainer = new WebMarkupContainer("groupNameContainer");
        groupNameContainer.add(new Label("groupName", m.getGroup().getGroupName()));
        groupList.add(groupNameContainer);
        repeater.add(groupList);                  
    }
    groupSelectionContainer.add(repeater);
    this.add(groupSelectionContainer);
}
}

Hope this helps.

I have one possible solution to your problem. Add a WebMarkupContainer :

final WebMarkupContainer panelContainer = new WebMarkupContainer("panelContainer");
panelContainer.setOutputMarkupId(true);

And in the html you will have it as:

<div wicket:id="panelContainer"></div>

Then you must add the panel to your markup container:

panelContainer.add(panel)

And add the markup container on the target instead of the panel:

target.addComponent(panelContainer);

If this doesn't work let me know and i will provide further assitance

When you target the panel the components in it will be refreshed. But what happens depends on how "ItemSelectionComponent" is using "avaiableGroups".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM