Button 如何在RepeatingView中重复按钮
如何将按钮添加到RepeatingView?其他组件(如Label)工作正常,但按钮渲染不正确 我的代码:Button 如何在RepeatingView中重复按钮,button,wicket,repeat,Button,Wicket,Repeat,如何将按钮添加到RepeatingView?其他组件(如Label)工作正常,但按钮渲染不正确 我的代码: RepeatingView repeatingView = new RepeatingView(componentId); for (...) { AjaxButton button = new AjaxButton(repeatingView.newChildId()) { ... }; repeatingView.add(button); }
RepeatingView repeatingView = new RepeatingView(componentId);
for (...) {
AjaxButton button = new AjaxButton(repeatingView.newChildId()) {
...
};
repeatingView.add(button);
}
编辑:
我决定创建一个自定义列,它可以在一行中呈现多个按钮。
我读到按钮必须包在面板上才能看到正确的视图。
假设自定义列的名称为MultiButtonColumn
原理如下:从obejct T中获取列表L,对于每个属性p,从L的项中创建按钮。文本按钮是P值
Java类:MultiButtonColumn.Java
/**
* @param <T>
* @param <L> list property
* @param <P> item property
*/
public abstract class MultiButtonColumn<T, L, P> extends AbstractColumn<T, String> {
private static final long serialVersionUID = 3512450712767559519L;
private List<Button> buttonList = new ArrayList<Button>();
private String propertyList;
private String property;
public MultiButtonColumn(IModel<String> displayModel, final String propertyList, final String property) {
super(displayModel);
this.propertyList = propertyList;
this.property = property;
}
@Override
public void populateItem(Item<ICellPopulator<T>> cellItem, String componentId, IModel<T> rowModel) {
List<L> list = (List<L>) new PropertyModel<L>(rowModel, propertyList).getObject();
cellItem.add(new RepeaterPanel(componentId, list));
cellItem.getParent().getParent().setOutputMarkupId(true);
}
protected abstract Button newButton(String id, PropertyModel<P> propertyModel);
private class RepeaterPanel extends Panel {
private static final long serialVersionUID = 1L;
public RepeaterPanel(String id, List<L> list) {
super(id);
RepeatingView listItems = new RepeatingView("repeaterPanel");
for (L l : list) {
add(new ButtonPanel(listItems.newChildId(), new PropertyModel<P>(l, property)));
}
add(listItems);
}
}
// wrap button to panel for correct view
private class ButtonPanel extends Panel {
private static final long serialVersionUID = 1L;
public ButtonPanel(String id, PropertyModel<P> propertyModel) {
super(id);
Button button = newButton("button", propertyModel);
buttonList.add(button);
add(button);
}
}
public List<Button> getButtonList() {
return buttonList;
}
}
我已经实现了类MultiLabelColumn。目的是相同的,在一行中呈现多个标签。这门课很好
MultiLabelColumn.java和MultiButtonColumn.java之间的区别在于,MultiButtonColumn包含2个面板(按钮包装在面板中,面板包装在Repeater面板中),而MultiLabelColumn仅包含1个面板(标签包装在RepeaterPanel中).由于没有关联的标记文件,因此会出现该错误。您需要创建一个
ButtonPanel.html
但是,我建议不要创建您的
RepeaterPanel
,而是使用一个,它已经具有您想要的功能。您可以为此代码添加html吗?RepeatingView是DataTable的一部分,由于呈现的行数多于一行,因此专门放在单元格中。文本是添加到按钮体中的
<?xml version="1.0" encoding="UTF-8" ?>
<wicket:panel xmlns:wicket="http://wicket.apache.org">
<div wicket:id="repeaterPanel" />
</wicket:panel>
Last cause: Failed to find markup file associated. ButtonPanel: [ButtonPanel [Component id = 1]]
Root cause:
org.apache.wicket.markup.MarkupNotFoundException: Failed to find markup file associated. ButtonPanel: [ButtonPanel [Component id = 1]]
at org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.getMarkup(AssociatedMarkupSourcingStrategy.java:97)
at org.apache.wicket.MarkupContainer.getMarkup(MarkupContainer.java:451)
at org.apache.wicket.Component.getMarkup(Component.java:743)
at org.apache.wicket.Component.getMarkupTag(Component.java:1389)
at org.apache.wicket.Component.getMarkupIdFromMarkup(Component.java:752)
.......