Primefaces数据表选择';如果未在对话框中呈现,则s属性为空

Primefaces数据表选择';如果未在对话框中呈现,则s属性为空,primefaces,Primefaces,我不确定这是我的限制还是编码错误。我有一个Primefaces数据表,允许用户选择它(单选),然后单击CommandButton在对话框中编辑数据 在显示所选对象的HTML代码中,我省略了ID、Lat和Long属性,因为人类用户不应该触摸这些属性。对话框正确地显示了所选属性,但是,当我试图使用所选对象的ID查找现有记录进行更新时,它抛出了一个无结果错误。当我检查所选对象的ID属性时,它的值为NULL 我对HTML代码进行了修改,发现为了将任何属性复制到所选对象,这些属性必须显示在XHTML中。当

我不确定这是我的限制还是编码错误。我有一个Primefaces数据表,允许用户选择它(单选),然后单击CommandButton在对话框中编辑数据

在显示所选对象的HTML代码中,我省略了ID、Lat和Long属性,因为人类用户不应该触摸这些属性。对话框正确地显示了所选属性,但是,当我试图使用所选对象的ID查找现有记录进行更新时,它抛出了一个无结果错误。当我检查所选对象的ID属性时,它的值为NULL

我对HTML代码进行了修改,发现为了将任何属性复制到所选对象,这些属性必须显示在XHTML中。当我使用Render=False包含属性时,该属性的值将为NULL。除了使用“禁用标记属性”之外,还有什么关于隐藏人类用户不应该修改的属性的建议吗

Class Property{
    Int ID;
    String Address;
    Long Lat;
    Long Long;
    String Desc;
}

public void modifyCurrentProject() {
    HashMap<String, Object> params = new HashMap();
    params.put("id", currentProject.getId());

    //fails to find Project by ID as currentProject.getID == null
    Project temp = (Project) dbu.findByNamedQuery("project.findID", params);

    //Omit statements to overwrite attached object's values before writing back to database 
    dbu.modifyEntity(); //dbu is another object to control database access
    currentProject = null;
}

<h:body>
    <p:growl id="projectMsg" showDetail="true"/>
    <h:form id="form">

        <p:dataTable id="projectTable" var="project" value="#{projectBacking.builder.projects}" selection="#{projectBacking.currentProject}" rowKey="#{project.id}">
            <f:facet name="header">My Project List
                <p:commandButton value="Add" type="button" onclick="PF('projectAdd').show()"/>
                <p:commandButton value="Edit" update=":editForm" oncomplete="PF('projectEdit').show()"/>
            </f:facet>

            <p:column selectionMode="single"/>   
            <p:column headerText="ID">
                <h:outputText value="#{project.id}"/>

            <p:column headerText="Description">
                <h:outputText value="#{project.property.description}"/>
            </p:column>

            <p:column headerText="Street">
                <h:outputText value="#{project.street}"/>
            </p:column>
            <p:column headerText="City">
                <h:outputText value="#{project.city}"/>
            </p:column>
            <p:column headerText="Province">
                <h:outputText value="#{project.state}"/>
            </p:column>

            <p:column headerText="Latitude">
                <h:outputText value="#{project.latitude}"/>
            </p:column>

            <p:column headerText="Longitude">
                <h:outputText value="#{project.longitude}"/>
            </p:column>

            <p:column headerText="Status">
                <h:outputText value="#{project.status}"/>
            </p:column>

        </p:dataTable>
    </h:form>

<!-- Omitted the Add Project Dialog box -->

    <p:dialog header="Edit Project" modal="true" height="400" width="80%" widgetVar="projectEdit">
        <h:form id="editForm">
            <p:panel id="editProject" header="Edit Project" toggleable="true" closable="false">
                <!--<h:inputText id="id" value="#{projectBacking.currentProject.id}"/>-->

                <h:inputText id="country" value="#{projectBacking.currentProject.country}"/>

                <h:inputText id="lat" rendered="true" value="#{projectBacking.currentProject.latitude}"/>

                <h:inputText id="long" rendered="true" value="#{projectBacking.currentProject.longitude}"/>

                <h:outputLabel for="desc" value="Description" />
                <h:inputText id="desc" value="#{projectBacking.currentProject.description}"/>

                <h:outputLabel for="street" value="Street" />
                <h:inputText id="street" value="#{projectBacking.currentProject.street}"/>
                <h:message for="street"/>

                <h:outputLabel for="city" value="City:" />
                <h:inputText id="city" required="false" value="#{projectBacking.currentProject.city}"/>
                <h:message for="city" />

                <h:outputLabel for="state" value="Province" />
                <h:inputText id="state" required="true" value="#{projectBacking.currentProject.state}"/>             

                <h:commandButton value="Save Project" type="submit" action="#{projectBacking.modifyCurrentProject()}">
                </h:commandButton>

            </p:panel>
        </h:form>
    </p:dialog>                  
</h:body>
类属性{
Int-ID;
字符串地址;
长Lat;
长长的;
字符串描述;
}
public void modifyCurrentProject(){
HashMap params=新的HashMap();
参数put(“id”,currentProject.getId());
//按ID查找项目失败,因为currentProject.getID==null
Project temp=(Project)dbu.findByNamedQuery(“Project.findID”,params);
//在写回数据库之前,省略语句以覆盖附加对象的值
modifyEntity();//dbu是控制数据库访问的另一个对象
currentProject=null;
}
我的项目列表

在代码中放置了更多断点后,我发现在保存对话框中的更改时,它正在创建一个新的支持bean。如果设置为Render=false、Disabled=true或ReadOnly=true,则不会设置新的支持bean对象的值,并保留对象构造函数中指定的初始值


基本上,原因是范围不正确。问题发生时,我正在使用请求范围。但是,更改到会话范围解决了此问题。

请添加您的对话框和您的托管(您获取数据的方式)我相信这将有助于理解此问题