有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

修改JSF UIComponent时未更改java实体属性

我有一个<h:dataTable>,列定义如下

<h:column>
    <f:facet name="header">
        <h:outputText value="Price"/>
    </f:facet>
    <h:outputText value="#{p.price}" rendered="#{not p.editable}"></h:outputText>
    <h:inputText value="#{p.price}" rendered="#{p.editable}"></h:inputText>
</h:column>

<h:dataTable>已成功填充

<h:dataTable id="userTable" value="#{gnome.productList}" 
             var="p">

支持bean #gnome是一个@ViewScopedbean,并且productList被加载到后构造函数中,并且具有一个普通的getter

@PostConstruct
public void init() {
    productList = gnomeFacade.findAll();
}

public List<Gnome> getProductList() {
    return productList;
}

当按下<h:commandLink><h:inputText>被呈现,它允许我修改字段中的数据。然后,应该使用在<h:dataTable>外部定义的<h:commandButton>来保存数据

<h:commandButton value="Save changes!" action="#{gnome.saveAction}"/>

调用此方法的

public String saveAction() {
    System.out.println("DEBUG: Trying to save edited gnome...");
    for (Gnome g : productList) {
        gnomeFacade.edit(g);
    }
    return null;
}

我在gnomeFacade.edit()方法中添加了一些调试打印输出,以便能够查看正在合并的数据。productList实体中的任何属性都没有与其新值一起保存。我最初的想法是<h:dataTable>productList的值上重复,但既然我已经将它加载到了后构造函数中,那就不应该是问题了

当我更改<h:inputText>中的值时,为什么属性的值没有更改

编辑: 满的xhtml文档: https://pastee.org/75t3e


共 (0) 个答案