Jsf Primefaces数据表不';t如果<;p:选择一个功能表>;及<;h:输出文本>;不一样

Jsf Primefaces数据表不';t如果<;p:选择一个功能表>;及<;h:输出文本>;不一样,jsf,primefaces,selectonemenu,Jsf,Primefaces,Selectonemenu,我有一个使用Primefaces 3.5的数据表,如图所示 现在我正在编辑id为43的第二行,如下所示 单击勾号(最右边的列)时,该行将被编辑,如下所示 可以很容易地注意到,州名从xxxx更改为zzz,但国家似乎保持不变,预计将从德国更新为美国 实际上,已经对数据库进行了更改,但是在rowEdit事件完成时,这些更改似乎没有反映到数据表中 要查看对国家/地区所做的更改,需要重新加载页面。只有重新加载此页面时,才会显示正确的数据,如图所示 这是列出国家/地区下拉框的列 <p:aja

我有一个使用Primefaces 3.5的数据表,如图所示

现在我正在编辑id为43的第二行,如下所示

单击勾号(最右边的列)时,该行将被编辑,如下所示

可以很容易地注意到,州名从
xxxx
更改为
zzz
,但国家似乎保持不变,预计将从
德国更新为
美国

实际上,已经对数据库进行了更改,但是在
rowEdit
事件完成时,这些更改似乎没有反映到数据表中

要查看对国家/地区所做的更改,需要重新加载页面。只有重新加载此页面时,才会显示正确的数据,如图所示


这是列出国家/地区下拉框的列

<p:ajax event="rowEdit" listener="#{stateManagedBean.onRowEdit}" update=":form:dataTable :form:systemMessages :form:messages" process=":form:dataTable :form:systemMessages :form:messages"/>
<p:ajax event="rowEditCancel" listener="#{stateManagedBean.onRowEditCancel}" update=":form:systemMessages :form:messages" process=":form:systemMessages :form:messages"/>


<p:column headerText="Country" sortBy="#{state.country.countryName}" filterBy="#{state.country.countryName}" filterMaxLength="45">                    
    <p:cellEditor>
        <f:facet name="output">
            <h:outputText value="#{state.country.countryName}" />
        </f:facet>
        <f:facet name="input">
            <p:selectOneMenu id="cmbCountryMenu" value="#{state.country.countryId}" rendered="true" editable="false" converter="#{longConverter}" converterMessage="The supplied value is incorrect." required="true" requiredMessage="Select an appropriate option." style="width:100%;">
                <f:selectItems var="country" value="#{stateManagedBean.countries}"  itemLabel="${country.countryName}" itemValue="${country.countryId}" itemLabelEscaped="true" rendered="true"/>
            </p:selectOneMenu>
        </f:facet>
    </p:cellEditor>
</p:column>
和的完整代码


rowEdit()
方法(如上所述)中,
stateTable.getCountry().getCountryId()
显示更新的
countryId
,但使用此国家对象引用相应的国家名称,如
stateTable.getCountry().getCountryName()
仅显示旧的国家名称(而不是更新的国家名称)。有什么办法可以解决这个问题


重要提示:

在上面的XHTML代码段中

<h:outputText value="#{state.country.countryName}"/>
                       ^^^^^^^^^^^^^_^^^^^^^^^^^
<p:selectOneMenu id="cmbCountryMenu" value="#{state.country.countryId}" .../>
                                              ^^^^^^^^^^^^^_^^^^^^^^^
然后,它会按预期工作(Primefaces展示示例就是这样演示的)



这与动态更新页脚值(显示列的数值总数)相同。更新该列中的行时,不会更新页脚。问题已报告。

问题在于您没有更改整个国家/地区对象。因为您使用
#{state.country.countryId}
作为
p:selectOneMenu
的值,所以只有当前所选国家的属性
countryId
正在更改,而不是国家,例如
countryName
等其他属性将保留

您必须将
p:selectOneMenu
的值更改为
{state.country}
,将
f:selectItems
itemValue
更改为
{country}
。查看for
p:selectOne菜单

此外,由于
country
是一个POJO,默认情况下没有可用的转换器,因此您必须实现
countryConverter
,并在通过
p:selectOneMenu
选择项目时将其用于转换

将以下代码用于
p:selectOneMenu
,并将其作为实现转换器的支持

<p:selectOneMenu id="cmbCountryMenu" value="#{state.country}" rendered="true" editable="false" converter="#{countryConverter}" converterMessage="The supplied value is incorrect." required="true" requiredMessage="Select an appropriate option." style="width:100%;">
    <f:selectItems var="country" value="#{stateManagedBean.countries}"  itemLabel="#{country.countryName}" itemValue="#{country}" itemLabelEscaped="true" rendered="true"/>
</p:selectOneMenu>


尝试遵循此示例,看看缺少什么。在该示例中,
的值与
value=“#{car.color}”
的值相同。这样做也适用于我的情况(在开始之前,我总是先查看showcase示例)。然而,在我的例子中,
的值是不同的,分别是
value=“{state.countryId.countryName}”
value=“{state.countryId.countryId}”
。这不符合预期。请将其放在表单上,然后在执行更改事件时更新表单。首先感谢您的回答,但很抱歉,我在这些更改中遇到了相同的问题。另外,BalusC的博客很棒,但是它使用了
List
,顺便说一下,这是一个旧的JSF1.x东西?你能发布你创建的转换器的代码吗?哦,对不起,我没看到。啊!这对我有用。现在我发现它非常简单,但只是在我实现之后。非常感谢。
<h:outputText value="#{state.country.countryId}"/>
                       ^^^^^^^^^^^^^_^^^^^^^^^
<p:selectOneMenu id="cmbCountryMenu" value="#{state.country.countryId}" .../>
                                              ^^^^^^^^^^^^^_^^^^^^^^^
<p:selectOneMenu id="cmbCountryMenu" value="#{state.country}" rendered="true" editable="false" converter="#{countryConverter}" converterMessage="The supplied value is incorrect." required="true" requiredMessage="Select an appropriate option." style="width:100%;">
    <f:selectItems var="country" value="#{stateManagedBean.countries}"  itemLabel="#{country.countryName}" itemValue="#{country}" itemLabelEscaped="true" rendered="true"/>
</p:selectOneMenu>