primefaces数据表行编辑不更新单元格元素 [英] primefaces datatable rowedit not updating cell element

查看:20
本文介绍了primefaces数据表行编辑不更新单元格元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 rowedit 的数据表.我的表格的一列是一个带有列表框的单元格,列表框的项目是动态检索的(取决于另一个单元格中的值)我使用 rowEditInit 来设置 selectedrow 项目.我想更新列表框以检索正确的值.这不起作用.当我这样做时

I have a datatable with rowedit. One column of my table is a cell with a listbox in, the items of the listbox are dynamically retrieved (depending on the value in another cell) I use rowEditInit to set the selectedrow item. And I want to update the listbox to retrieve the correct values. This does not work. When I do

<p:ajax event="rowEditInit" listener="#{workOrderDetail.onEdit}" update="orderitemstable" />

然后,当我单击铅笔图标时,我可以看到行切换到编辑模式并检索列表框项目.但它直接切换回非编辑模式.

Then when I click the pencil icon, the I can see the row switch to edit mode and retriving the listbox items. But it directly swithced back to non edit mode.

但是当我这样做时

<p:ajax event="rowEditInit" listener="#{workOrderDetail.onEdit}" update="rmactionenumid" />

然后单击铅笔图标将该行置于编辑模式,但不会调用检索列表框项目.我的猜测是,它不会触发 rmactionenumid 上的更新.

Then clicking the pencil icon puts the row in edit mode, but no call is made to retrieve the listbox items. My gues is, it does not trigger the update on rmactionenumid.

有什么想法吗?

罗尔

这是我的 jsf 代码

Here is my jsf code

            <p:ajax event="rowEditInit" listener="#{workOrderDetail.onEdit}" update="rmactionenumid" />


            <p:column >  
                <p:cellEditor>  
                    <f:facet name="output">  
                        <h:outputText id="rmactionenumidlabel" value="#{orderItem.rmActionRepr}" >
                        </h:outputText>
                    </f:facet>  
                    <f:facet name="input">  
                        <h:selectOneListbox id="rmactionenumid" value="#{orderItem.rmActionEnumId}" size="1" valueChangeListener="#{workOrderDetail.setActionRepr}">
                            <f:selectItems value="#{workOrderDetail.actionItems}"/> 
                            <p:ajax event="change" update="partdiscount,labourdiscount,totalprice,:detail:wodetail:totals" execute="@this"  />                                  
                        </h:selectOneListbox>   

                    </f:facet>  
                </p:cellEditor>  
            </p:column>
<p:column >
<p:rowEditor id="edit"  />                          
                </p:commandLink>

            </p:column>  
        </p:dataTable>

这是我的 java bean 代码

and here is my java bean code

public List<SelectItem> getActionItems() throws MWSException {
    ArrayList<SelectItem> actions = new ArrayList<SelectItem>();
    if (getSelectedOrderItem() != null) {

        ListManager lm = new ListManager(getWA().getMwsProxy());
        MWSGenericMapList items = lm.nativeSearch(getWS().getUser(), HdfWebConstants.NS_VEHICLEPARTACTIONS, 0, 0, 200,
                false, getSelectedOrderItem().getVehiclePartCode());

        for (int i = 0; i < items.size(); i++) {
            actions.add(new SelectItem(items.get(i).get("rmaction_enumid").toString(), items.get(i).get("rmaction")
                    .toString()));
        }

    }
    return actions;
}

public void setSelectedOrderItem(IMWSOrderItem newSelectedOrderItem) throws MWSException {
    this.selectedOrderItem = newSelectedOrderItem;
}

public void onEdit(RowEditEvent event) throws MWSException {

    setSelectedOrderItem((IMWSOrderItem) event.getObject());

}

我正在使用 PF3.5

I'm using PF3.5

推荐答案

失败是因为 update="rmactionenumid" 在这个结构中是相对于表本身,而不是相对于当前表行.

It fails because update="rmactionenumid" is in this construct relative to the table itself, not to the current table row.

基本上,它正在寻找具有客户端 ID formId:tableId:rmactionenumid 的组件,而不是例如第二行 formId:tableId:1:rmactionenumid.从技术上讲,<p:ajax> 应该放在 <p:column> 内,但这不适用于 rowEditInit 事件.

Basically, it's looking for a component with client ID formId:tableId:rmactionenumid instead of e.g. the second row formId:tableId:1:rmactionenumid. Technically, the <p:ajax> should be placed inside the <p:column>, but this won't work out for rowEditInit event.

您需要根据 UIData 组件编写自己的 update 客户端 ID,该组件可用作 RowEditEvent 参数并添加已编写的PartialViewContext 的客户端 ID#getRenderIds().

You'd need to compose your own update client ID based on the UIData component which is available as RowEditEvent argument and add the composed client ID to PartialViewContext#getRenderIds().

所以,删除 <p:ajax update> 并扩展 onUpdate() 方法如下:

So, remove the <p:ajax update> and extend the onUpdate() method as follows:

public void onEdit(RowEditEvent event) {
    UIData table = (UIData) event.getComponent();
    String updateClientId = table.getClientId() + ":" + table.getRowIndex() + ":rmactionenumid";
    FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add(updateClientId);

    // ...
}

这篇关于primefaces数据表行编辑不更新单元格元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆