简体   繁体   English

更新JSF(AJAX)中的子组件

[英]Update child component in JSF (AJAX)

I want update subcomponent with id="two". 我想要使​​用id =“ two”更新子组件。 Everything is working until i put form in another component like h:panelGrid. 一切正常,直到我将表单放在另一个组件中,例如h:panelGrid。

<h:panelGroup id="one">
    <h:panelGroup id="two">
        <h:outputText value="#{testBean.num}"/>
    </h:panelGroup>
</h:panelGroup>

<br/>

<h:panelGrid columns="1">
    <h:form>
        <p:commandButton value="update" 
                         action="#{testBean.inc()}"
                         update=":one:two"
                         ajax="true"
                         />
    </h:form>
</h:panelGrid>

In this case i am getting: SF1073: java.lang.IllegalArgumentException caught during processing of RENDER_RESPONSE 6 : UIComponent-ClientId=, Message=one 在这种情况下,我得到:SF1073:在处理RENDER_RESPONSE 6期间捕获到java.lang.IllegalArgumentException:UIComponent-ClientId =,Message = one

What is wrong ? 怎么了 ?

PS: update=":one" is works, but i dont want update whole "one" component. PS:update =“:one”是可行的,但我不想更新整个“一个”组件。 错误堆栈跟踪

Here is a full code. 这是完整的代码。

xhtml page: xhtml页面:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <h:panelGroup id="one">
            <h:panelGroup id="two">
                <h:outputText value="#{testBean.num}"/>
            </h:panelGroup>
        </h:panelGroup>

        <br/>

        <h:panelGrid columns="1" id="table">
            <h:form id="form">
                <p:commandButton value="update" 
                                 action="#{testBean.inc()}"
                                 update=":one:two"
                                 ajax="true"
                                 />
            </h:form>
            <!-- .....another components .... -->
        </h:panelGrid>
    </h:body>
</html>

the bean: 豆:

@Named
@ViewScoped
public class TestBean implements Serializable{
    private int num;

    public void inc() {
        System.out.println("inc");
        num++;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }
}

This very unhelpful error is caused by your invalid update syntax: :one:two first tries to look up one as a NamingContainer (see Communications in JSF 2.0 ). 这个非常无用的错误是由无效的update语法引起的:one:two首先尝试将one查找为NamingContainer (请参见JSF 2.0中的Communications )。 If it finds the component, but it isn't a NamingContainer , it throws the exception you're seeing. 如果找到了组件,但它不是NamingContainer ,它将引发您所看到的异常。

To fix this, simply specify the correct update value: 要解决此问题,只需指定正确的更新值:

<p:commandButton value="update" action="#{testBean.inc()}"
  update=":two" ajax="true" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM