- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在 Wicket 口中创建一个动态表格组件来显示对象列表。该组件将接收对象列表并将其呈现为表格形式。
假设以下产品实体:
public class Product {
public static final long serialVersionUID = 1L;
//
private String id;
private String name;
private String description;
private Double price;
// getters and setters omitted for brevity
}
以下 html/代码对将起作用:
(注意:产品实体稍后将被泛化,因此我们可以向其传递任何 POJO 的列表)
<table>
<tbody>
<tr wicket:id="row">
<td wicket:id="cell">
cell
</td>
</tr>
</tbody>
</table>
----------------------------------------------------------------
parameters:
final String[] fieldNames = new String[]{"id", "name", "description", "price"};
List<Product> productList = ....
----------------------------------------------------------------
ListView lvRows = new ListView("row", productList) {
@Override
protected void populateItem(ListItem item) {
Product product = (Product)item.getModelObject();
CompoundPropertyModel cpm = new CompoundPropertyModel(product);
//
RepeatingView cell = new RepeatingView("cell", cpm);
item.add(cell);
//
for (String fn : fieldNames) {
Label label = new Label(fn);
cell.add(label);
}
}
};
this.add(lvRows);
问题是上面的代码将导致一堆警告(列表中的每个产品一个):
00:57:52.339 [http-apr-8080-exec-108] WARN o.a.w.m.repeater.AbstractRepeater - Child component of repeater org.apache.wicket.markup.repeater.RepeatingView:cell has a non-safe child id of id. Safe child ids must be composed of digits only.
所以我的问题是:
我做错了吗?
如果没有,我该如何摆脱警告?
为什么在此实例中 wicket 需要数字子 ID?通过将 id 链接到对象属性,CompoundPropertyModel 在其他情况下工作正常...
如果我做错了,“正确”的方法是什么?我应该唯一地创建子 id,放弃使用CompoundPropertyModel,并直接通过反射提供值吗?但不确定对性能的影响,为每个单元进行反射调用并不便宜。像这样的事情:
for(String fn:fieldNames} {
String s = ...; //find the value of Object O, property fn via Reflection
Label label = new Label(cell.newChildId(), s);
cell.add(label);
}
提前致谢。
最佳答案
您可以通过在 RepeatingView
中添加中间子项来避免警告。 ,正如 Igor Vaynberg 在 this post 中所解释的那样在 Wicket 用户列表中。
换句话说,不要添加 Label
将具有非数字 id 的容器直接添加到中继器,添加一个具有数字 id 的容器,然后添加 Label
到容器:
RepeatingView cell = new RepeatingView("cell");
WebMarkupContainer container = new WebMarkupContainer(cell.newChildId(), cpm);
for (String fn : fieldNames) {
Label label = new Label(fn);
container.add(label);
}
cell.add(container);
item.add(cell);
该帖子中还概述了这些警告的原因。
编辑:
看来您需要建模 ProductPanel
并在RepeatingView
内使用它而不仅仅是 WebMarkupContainer
。这意味着ProductPanel
可能必须在其 HTML 中显式枚举属性(或 wicket:id
s)。
您也可以保留当前代码并执行Label label = new Label(cell.newChildId(), new PropertyModel(product, fn));
如果您希望 HTML 独立于特定属性,请删除 CPM。
关于java - Wicket - 生成动态表 - ChildId 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20879616/
过去,我为我的表单构建了如下标签: : 我还需要使用wicket:label吗?标签?我没有使用 wicket:label在 wicket 7 中,它似乎工作正常。我可能不理解使用 wicket:la
是否可以为 MarkupContainer 生成标记?动态地,即不为其存储 HTML 文件? 我考虑将标记作为纯字符串从数据库中读取,以提供类似 CMS 的功能。 最佳答案 有趣的问题,我不确定这是否
是否有适用于 Wicket 1.5 的有效、支持和维护的脚手架解决方案?我知道 Wicketopia 位于两个不同地点 sourceforge和 github但这仍然针对 wicket 1.4,带来了
我想了解一些关于 wicket 支持泛型模型的信息。我了解了模型、 Prop 模型和 Prop 复合模型。 但是 Model 类呢?如果我这样做会发生什么: Label label = new Lab
如何在 Wicket 中实现多选下拉。我能够使用 bootstrap 创建多选下拉 View ,但我无法获得如何将所选选项与下拉组件的 IModel 相关联? Wicket 有没有可能?我不想使用 L
我正在使用 wicket 1.4.9 并实现了 spring + wicket auth-role 并根据页面上的角色使用@AuthorizeInstantiation。我有多个自定义角色。 我已经按
如何在 Wicket 1.5 中执行以下操作? page.getRequestCycle().setRequestTarget(new RedirectRequestTarget("http://ww
我想用密码保护 Wicket 中的网页,以便用户只有在他/她登录后才能访问它。 我还希望该页面显示登录页面,然后在登录用户试图访问的原始页面后。 这是如何用 wicket 完成的?我已经创建了一个登录
我使用的是 wicket 1.5,但在 getClientInfo() 方法中看不到 (WebRequest)RequestCycle.get().getRequest() 我在另一个地方看到了这段代
我刚刚尝试了 Apache Wicket“Hello, world”应用程序,我注意到在呈现的 HTML 输出中,Wicket 暴露了它的内部属性。 这是呈现的 HTML 在浏览器的“查看源代码”中的
我找不到像 wicket:include 之类的 wicket 标签?谁能建议我什么?我想在 html 文件中包含/注入(inject)原始源代码?如果没有这样的实用程序,有什么建议来开发它吗? 更新
在页面中查找特定(已知 wicket id)Wicket 组件的方法是什么? 最佳答案 您的选择是: get()搜索一个组件的方法 特定路径上的组件。 安 iterator()在拥有他所有 child
我正在为 wicket 页面编写测试。我的页面上有三个下拉菜单。根据从下拉列表中选择的值,面板会被渲染(面板包含一个数据表)。 如何更改 wicket 测试中下拉菜单的值,以便我可以针对所选值的不同组
在我的 wicket 应用程序中,有一些页面供用户使用,具体取决于他们的角色和不同的标准。在我的数据库中,我存储了用作该用户背景的图像路径。每个用户都有一个独特的页面。我知道我可以添加读取图像,如果我
如何在 Wicket 中定义我自己的反馈消息? 例如:如果我提供了一个错误的用户名,我想得到一个错误信息,如“用户名不正确,请尝试再次登录”。而不是使用默认的错误消息。 一个例子会是什么样的? 最佳答
假设我想要 3 个不同的 *.html 用于 WebPage。 F.e. page_small.html、page_tablet.html、page_desktop.html。我如何解析 screen
我无法确定 Wicket 应用程序中 RuntimeException 的原因。我设置了许多断点,但是当我提交表单时,只有在加载表单时,没有一个断点被触发。这是堆栈: WicketMessage: N
我刚刚编写了我的第一个 Wicket 组件 :) 它包含一个 ListView 和一些 Radio 输入字段。现在我想对所选值是否进入模型进行单元测试。 由于 WicketTester.newForm
我的类属性有两个 CSS 类值。 HTML 开头是这样的: 我想动态地把它改成这样: 目前我正在这样做: component.add(new SimpleAttributeModifier("cl
我有一个使用 PropertyModel 的文本字段,如下所示: TextField ageField = new TextField("age", new
我是一名优秀的程序员,十分优秀!