Java 导叶面板没有';无法在按钮提交时获取刷新
添加新组后,我需要刷新面板(在下面的代码中已声明为面板)。Java 导叶面板没有';无法在按钮提交时获取刷新,java,refresh,wicket,Java,Refresh,Wicket,添加新组后,我需要刷新面板(在下面的代码中已声明为面板)。ItemSelectionComponent组件是一个不同的面板,其中包含特定人员的添加组。我需要做的是,一旦我添加了一个新的组,这个特定的面板(带有wicket id的ItemSelectionComponent面板“)应该被刷新,并且新添加的组应该被显示出来 我目前使用 target.addComponent(面板) 刷新,但似乎不起作用:( 有人能告诉我怎么了吗? 谢谢!对于您的问题,我有一个可能的解决方案。 添加一个WebMark
ItemSelectionComponent
组件是一个不同的面板
,其中包含特定人员的添加组。我需要做的是,一旦我添加了一个新的组,这个特定的面板(带有wicket id的ItemSelectionComponent
面板“)应该被刷新,并且新添加的组应该被显示出来我目前使用
target.addComponent(面板)代码>
刷新,但似乎不起作用:(
有人能告诉我怎么了吗?
谢谢!对于您的问题,我有一个可能的解决方案。
添加一个WebMarkupContainer:
final WebMarkupContainer panelContainer = new WebMarkupContainer("panelContainer");
panelContainer.setOutputMarkupId(true);
在html中,您将看到:
<div wicket:id="panelContainer"></div>
并在目标而不是面板上添加标记容器:
target.addComponent(panelContainer);
如果这不起作用,请让我知道,我将提供进一步的帮助对于您的问题,我有一个可能的解决方案。
添加一个WebMarkupContainer:
final WebMarkupContainer panelContainer = new WebMarkupContainer("panelContainer");
panelContainer.setOutputMarkupId(true);
在html中,您将看到:
<div wicket:id="panelContainer"></div>
并在目标而不是面板上添加标记容器:
target.addComponent(panelContainer);
如果这不起作用,请告诉我,我将提供进一步的帮助。当您以面板为目标时,面板中的组件将被刷新。但发生的情况取决于“ItemSelectionComponent”如何使用“AvailableGroups”。当您以面板为目标时,面板中的组件将被刷新。但发生的情况取决于如何更新“ItemSelectionComponent”正在使用“AvailableGroups”。您的AvailableGroups应该是一个LoadableDetachableModel,其中包含您的GroupSelectionModels列表。使用AjaxSubmitLink时,从LoadableDetachableModel获取列表并添加到列表中
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);
}
};
LoadableDetachableModel LDM=新的LoadableDetachableModel(){
私有静态最终长serialVersionUID=1L;
@凌驾
受保护的字符串加载(){
返回ServiceLocator.getInstance().find(GroupService.class).getAllGroups();;
}
};
AjaxSubmitLink addBtn=新的AjaxSubmitLink(“addBtn”){
@凌驾
提交时受保护的void(AjaxRequestTarget,表格f){
List currentGroups=ServiceLocator.getInstance().find(GroupService.class).getAllGroups();
组=新组();
group.setGroupType(group.GroupType.EMAIL);
组。设置商户(商户);
setGroupName(form.getModelObject().getGroupName());
ServiceLocator.getInstance().find(GroupService.class).saveGroup(group);
GroupSelectionModel newGroup=新的GroupSelectionModel();
newGroup.setGroup(组);
newGroup.setGroupSelected(true);
LDM.getObject().add(newGroup);
目标组件(面板);
}
};
然后将LDM作为参数传递给ItemSelectionComponent,而不是AvailableGroups。在ItemSelectionComponent中使用LDM就像在AvailableGroups中使用LDM一样
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);
}
}
公共类ItemSelectionComponent扩展面板{
私有静态最终长serialVersionUID=6670144847L;
私有可加载可分离模型;
PublicItemSelectionComponent(字符串id,LoadableDetachableModel){
超级(id);
this.model=模型;
init();
}
私有void init(){
WebMarkupContainer groupSelectionContainer=新的WebMarkupContainer(“groupSelectionContainer”);
RepeatingView repeater=新RepeatingView(“组列表”);
WebMarkupContainer组列表;
对于(最终组SelectionModel m:model.getObject()){
groupList=newWebMarkupContainer(repeater.newChildId());
WebMarkupContainer groupNameContainer=新的WebMarkupContainer(“groupNameContainer”);
添加(新标签(“groupName”,m.getGroup().getGroupName());
添加(groupNameContainer);
repeater.add(组列表);
}
groupSelectionContainer.add(中继器);
此.add(groupSelectionContainer);
}
}
希望这有帮助。您的可用组应该是一个LoadableDetaccableModel,其中包含您的GroupSelectionModels列表。当您使用AjaxSubmitLink时,请从LoadableDetaccableModel获取列表并添加到其中
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);
}
};
LoadableDetachableModel LDM=新的LoadableDetachableModel(){
私有静态最终长serialVersionUID=1L;
@凌驾
受保护的字符串加载(){
返回ServiceLocator.getInstance().find(GroupService.class).getAllGroups();;
}
};
AjaxSubmitLink addBtn=新的AjaxSubmitLink(“addBtn”){
@凌驾
提交时受保护的void(AjaxRequestTarget,表格f){
List currentGroups=ServiceLocator.getInstance().find(GroupService.class).getAllGroups();
组=新组();
group.setGroupType(group.GroupType.EMAIL);
组。设置商户(商户);
setGroupName(form.getModelObject().getGroupName());
ServiceLocator.getInstance().find(GroupService.class).saveGroup(group);
GroupSelectionModel newGroup=新的GroupSelectionModel();
newGroup.setGroup(组);
newGroup.setGroupSelected(true);
LDM.getObject().add(newGroup);
目标组件(面板);
}
};
然后将LDM作为参数传递给ItemSelectionComponent,而不是AvailableGroups。在ItemSelectionComponent中使用LDM就像在AvailableGroups中使用LDM一样
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);
}
}
公共类ItemSelectionComponent扩展面板{
私有静态最终长serialVersionUID=6670144847L;
私有可加载可分离模型;
PublicItemSelectionComponent(字符串id,LoadableDetachableModel){
超级(id);
this.model=模型;
init();
}
私有void init(){
WebMarkupContainer groupSelectionContainer=新的WebMarkupContainer(“groupSelectionContainer”);
RepeatingView repeater=新RepeatingView(“组列表”);
WebMarkupContainer组列表;
对于(最终组选择模式