简体   繁体   English

<f:ajax render>不通过工作<composite:clientBehavior>

[英]<f:ajax render> not working via <composite:clientBehavior>

I have a composite component which has ajax: 我有一个具有ajax的复合组件:

<composite:interface>
    <composite:attribute name="question" required="true"/>
    <composite:attribute name="value" required="false"/>
    <composite:attribute name="id" required="true" />
    <composite:clientBehavior name="alter" 
        event="change" targets="input"/>
</composite:interface>
<composite:implementation>
    <label for="#{cc.attrs.id}">
        <h:outputText value="#{cc.attrs.question}" />
    </label>
    <div class="fld">      
        <h:selectOneRadio value="#{cc.attrs.value}" id="input">
            <f:selectItem itemValue="true" itemLabel="Yes" />
            <f:selectItem itemValue="false" itemLabel="No" />
        </h:selectOneRadio>
    </div>
</composite:implementation>

when I am using this composite component in my page like so: 当我在我的页面中使用这个复合组件时,如下所示:

<question:yesNo question="#{myMSG['knowRegQuestion']}" value="#{vehicle.regKnown}" id="is-reg-known">
    <f:ajax event="alter" render="reg-unknown" />
</question:yesNo>
......
<h:panelGroup id="reg-unknown" styleClass="questionGroup man-veh-srch">
    ......
    <h:selectOneListbox value="#{vehicle.model}" size="1" rendered="#{vehicle.regKnown eq 'true'}">
        ......
    </h:selectOneListbox>
</h:panelGroup>

The ajax is firing, the model is being updated correctly but the rendering does not change. ajax正在触发,模型正在正确更新,但渲染不会改变。 (I have tried various EL expressions) Also the ajax response does not look correct in firebug: (我尝试过各种EL表达式)另外abax响应在firebug中看起来不正确:

<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1"><changes><update id="j_id1:javax.faces.ViewState:0"><![CDATA[-2911901889097730230:4227240037100614528]]></update></changes></partial-response>

What have I missed? 我错过了什么? (thanks) (谢谢)

Any relative client ID which is specified in <f:ajax render> is resolved relative to the parent ClientBehaviorHolder component in the component tree. <f:ajax render>指定的任何相对客户端ID都是相对于组件树中的父ClientBehaviorHolder组件解析的。 In your particular case, this is actually the <h:selectOneRadio> . 在您的特定情况下,这实际上是<h:selectOneRadio> The component with client ID reg-unknown is thus being sought in the same naming container parent as the <h:selectOneRadio> , which is the <cc:implementation> itself (you probably already know that composite components implement NamingContainer ). 因此,在与<h:selectOneRadio>相同的命名容器父中寻找具有客户端ID reg-unknown的组件,这是<cc:implementation>本身(您可能已经知道复合组件实现了NamingContainer )。 However, the desired component isn't in there. 但是,所需的组件不在那里。

You'd better specify an absolute client ID instead (thus, starting with : , so that it would be sought relative to the UIViewRoot ). 您最好指定一个绝对客户端ID(因此,从:开始,以便相对于UIViewRoot寻找它)。 You can achieve this in two general ways: 您可以通过两种通用方式实现此目的:

  1. Hardcode it (assuming that this all is inside a form with ID form ): 硬编码(假设这一切都在ID form ):

     <h:form id="form"> <question:yesNo ...> <f:ajax event="alter" render=":form:reg-unknown" /> </question:yesNo> ... <h:panelGroup id="reg-unknown" ...> ... </h:panelGroup> </h:form> 
  2. Reference UIComponent#getClientId() (in case ID of parent naming container isn't known): 引用UIComponent#getClientId() (如果父命名容器的ID未知):

     <h:form ...> <question:yesNo ...> <f:ajax event="alter" render=":#{regUnknown.clientId}" /> </question:yesNo> ... <h:panelGroup binding="#{regUnknown}" ...> ... </h:panelGroup> </h:form> 

This is indeed awkward. 这确实很尴尬。 This was ever reported as Mojarra issue 1510 , but they didn't consider it to be a bug as the composite component itself isn't supposed to know anything about other components outside the composite component (although the solution would be theoretically simple: if the <f:ajax render> doesn't start with : or @ , then prefix it with the client ID of the composite component's parent). 这曾被报道为Mojarra 问题1510 ,但他们并不认为它是一个错误,因为复合组件本身不应该对复合组件之外的其他组件有任何了解(尽管解决方案理论上很简单:如果<f:ajax render>不以:@开头,然后用复合组件父级的客户端ID作为前缀。

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

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