如果未在 JDK1.5 中设置 ID,则不会从可编辑数据表中更新绑定值

发布于 2024-11-26 16:56:13 字数 1411 浏览 7 评论 0原文

如果未在 JDK 1.5 中设置 ID,则不会从可编辑数据表中更新绑定值。但在 JDK 1.6 中无需设置 ID 也同样可以工作。 有谁知道为什么?感谢

代码,Bean部分

    public void setDataTable(HtmlDataTable dataTable) {
    this.dataTable = dataTable;
}

public HtmlDataTable getDataTable() {
    if (dataTable == null)
        setEditableDataTable();
    return dataTable;
}

private void setEditableDataTable() {

    dataTable = new HtmlDataTable();
    dataTable.setValueBinding("value",
            createValuebinding("#{testBean.stringList}"));
    dataTable.setVar("items");
    for (int i = 0; i < getDatastable().get(i).size(); i++) {

        UIColumn column = new UIColumn();
        dataTable.getChildren().add(column);

        HtmlOutputText header = new HtmlOutputText();
        header.setValue("Header "+i);
        column.setHeader(header);

        HtmlInputText input = new HtmlInputText();
        input.setValueBinding("value", createValuebinding("#{items[" + i
                + "]}"));
        column.getChildren().add(input);

    }

}

private ValueBinding createValuebinding(String valueExpression) {
    return FacesContext.getCurrentInstance().getApplication()
            .createValueBinding(valueExpression);
}

JSP部分

   <h:dataTable binding="#{testBean.dataTable}" >
                </h:dataTable>

解决方案

   Give id for the datatable

Bound values are not getting updated from editable data table without setting ID in JDK 1.5. But the same does work without setting ID in JDK 1.6.
Does anyone know why? Thanks

Code, Bean part

    public void setDataTable(HtmlDataTable dataTable) {
    this.dataTable = dataTable;
}

public HtmlDataTable getDataTable() {
    if (dataTable == null)
        setEditableDataTable();
    return dataTable;
}

private void setEditableDataTable() {

    dataTable = new HtmlDataTable();
    dataTable.setValueBinding("value",
            createValuebinding("#{testBean.stringList}"));
    dataTable.setVar("items");
    for (int i = 0; i < getDatastable().get(i).size(); i++) {

        UIColumn column = new UIColumn();
        dataTable.getChildren().add(column);

        HtmlOutputText header = new HtmlOutputText();
        header.setValue("Header "+i);
        column.setHeader(header);

        HtmlInputText input = new HtmlInputText();
        input.setValueBinding("value", createValuebinding("#{items[" + i
                + "]}"));
        column.getChildren().add(input);

    }

}

private ValueBinding createValuebinding(String valueExpression) {
    return FacesContext.getCurrentInstance().getApplication()
            .createValueBinding(valueExpression);
}

JSP part

   <h:dataTable binding="#{testBean.dataTable}" >
                </h:dataTable>

Solution

   Give id for the datatable

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文