Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 使用p:remote命令更新p:dataTable_Jsf_Primefaces_Jsf 2.2_Remotecommand - Fatal编程技术网

Jsf 使用p:remote命令更新p:dataTable

Jsf 使用p:remote命令更新p:dataTable,jsf,primefaces,jsf-2.2,remotecommand,Jsf,Primefaces,Jsf 2.2,Remotecommand,给定以下XHTML代码,该代码有一个和一个只有两列 <p:remoteCommand name="updateTable" update="dataTable"/> <p:panel id="panel"> <p:inputText id="txtValue" value="#{testManagedBean.txtValue}" required="true"/> <p:message for="tx

给定以下XHTML代码,该代码有一个
和一个
只有两列

<p:remoteCommand name="updateTable" update="dataTable"/>

<p:panel id="panel">
    <p:inputText id="txtValue" value="#{testManagedBean.txtValue}"
                 required="true"/>
    <p:message for="txtValue" showSummary="false"/>
    <p:commandButton actionListener="#{testManagedBean.submitAction}"
                     oncomplete="if(!args.validationFailed) {updateTable();}" 
                     update="panel" value="Submit"/>
</p:panel>

<p:panel id="dataTablePanel" header="Data">
    <p:dataTable id="dataTable" var="row" value="#{testManagedBean}"
                 lazy="true"
                 pageLinks="10"
                 editable="true"
                 rowsPerPageTemplate="5,10,15"
                 rows="10"
                 rowKey="#{row.catId}"
                 editMode="row">

        <p:ajax event="rowEdit" update=":form:panel dataTable"
                listener="#{testManagedBean.onRowEdit}"/>

        <p:column id="id" headerText="Id">
            <h:outputText value="#{row.catId}"/>
        </p:column>

        <p:column id="catName" headerText="Category">
            <p:cellEditor>
                <f:facet name="output">
                    <h:outputText value="#{row.catName}"/>
                </f:facet>
                <f:facet name="input">
                    <p:inputText value="#{row.catName}" label="Category">
                        <f:validateLength minimum="2" maximum="45"/>
                    </p:inputText>
                </f:facet>
            </p:cellEditor>
        </p:column>

        <p:column headerText="Edit" width="100">
            <p:rowEditor/>
        </p:column>
    </p:dataTable>
</p:panel>
删除
oncomplete=“if(!args.validationFailed){updateTable();}”

并且
update
属性从
update=“panel”
更改为
update=“panel dataTable”
,然后,更新
中的行时,
不会导致验证

当使用
更新
中的一行时,如何防止
执行验证,而
又会更新持有相关

在这种情况下,不能忽略它本身。只有在没有违反验证的情况下,才有必要更新
。否则,即使存在验证错误,也会不必要地执行代价高昂的业务服务


相关联的JSF托管bean(尽管完全没有必要)

@ManagedBean
@视域
公共最终类TestManagedBean扩展LazyDataModel实现可序列化
{
@EJB
private final CategoryBeanLocal categoryService=null;
私有字符串txtValue;//Getter和setter。
私有静态最终长serialVersionUID=1L;
@凌驾
公共列表加载(int-first、int-pageSize、列表多端口元、映射过滤器){
setRowCount(categoryService.rowCount().intValue());
return categoryService.getList(第一个,pageSize,multiportmeta,filters);
}
公开无效提交(){
System.out.println(“txtValue:+txtValue”);
txtValue=null;
}
公共无效onRowEdit(RowEditEvent事件){
System.out.println(“调用了onRowEdit());
}
}
执行此操作后,如果给定的
所持有的行被更新(这反过来又通过
内部的
更新
。有时是必要的),则
中的给定
会导致验证其边框变为红色,这意味着违反了不应发生的相关验证

这不是正在发生的事情。如果这是真的,您将在网络监视器中看到3个HTTP请求。但只有两个(一个来自小组提交,一个来自

原因是
本身。它的
进程
属性为
@all
(“整个视图”)。您还可以通过检查网络监视器中的
javax.faces.partial.execute
request参数来确认这一点。上面写着
@all
。换句话说,整个表单也被提交/处理,包括那些空输入

您需要将其显式设置为
@this

<p:remoteCommand name="updateTable" process="@this" update="dataTable"/>

作为usaul,不仅仅是一个答案,还有完整的技术解释。谢谢
@ManagedBean
@ViewScoped
public final class TestManagedBean extends LazyDataModel<Category> implements Serializable
{
    @EJB
    private final CategoryBeanLocal categoryService = null;
    private String txtValue;  //Getter and setter.
    private static final long serialVersionUID = 1L;

    @Override
    public List<Category> load(int first, int pageSize, List<SortMeta> multiSortMeta, Map<String, Object> filters) {
        setRowCount(categoryService.rowCount().intValue());
        return categoryService.getList(first, pageSize, multiSortMeta, filters);
    }

    public void submitAction() {
        System.out.println("txtValue : " + txtValue);
        txtValue = null;
    }

    public void onRowEdit(RowEditEvent event) {
        System.out.println("onRowEdit() called.");
    }
}
<p:remoteCommand name="updateTable" process="@this" update="dataTable"/>