本文介绍了< F:AJAX渲染>通过与其中不工作;复合材料:clientBehavior>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复合材料部件,其具有AJAX:

I have a composite component which has 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>

阿贾克斯被解聘,该模型被正确更新,但呈现并不更改。 (我曾尝试过各种EL EX pressions)也Ajax响应看起来不正确的萤火虫:

The ajax is firing, the model is being updated correctly but the rendering does not change. (I have tried various EL expressions) Also the ajax response does not look correct in 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)

推荐答案

这是在&LT指定任何相对委托人身份证; F:AJAX渲染&GT; 是相对的解析为家长 ClientBehaviorHolder 组件的组件树。在特定的情况下,这实际上是&LT; H:selectOneRadio&GT; 。与客户端ID的组件 REG-未知因此正寻求在相同的命名容器的父为&LT; H:selectOneRadio&GT; ,这是&LT; CC:实施&GT; 本身(你可能已经知道,复合组件实现的)。然而,所希望的组分不是在那里。

Any relative client ID which is specified in <f:ajax render> is resolved relative to the parent ClientBehaviorHolder component in the component tree. In your particular case, this is actually the <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). However, the desired component isn't in there.

您最好指定一个绝对的客户端ID,而不是(因此,从,所以,这将是相对力求在 UIViewRoot )。您可以通过两种方式一般实现这一目标:

You'd better specify an absolute client ID instead (thus, starting with :, so that it would be sought relative to the UIViewRoot). You can achieve this in two general ways:

  1. 硬code它(假设这一切都是与身份证件放在表格):

<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>

  • 参考 UIComponent#getClientId()(父命名容器的情况下,ID是不知道):

  • Reference UIComponent#getClientId() (in case ID of parent naming container isn't known):

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

  • 这的确是尴尬。这是以往任何时候都报告为Mojarra 问题1510 ,但他们并不认为这是一个错误的复合组件本身是不应该知道的复合成分外的其他成分任何东西(尽管该解决方案在理论上是简单的:如果&LT; F:AJAX渲染&GT; 不是以 @ ,然后与客户端ID preFIX它的复合材料构件的父)。

    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).

    这篇关于&LT; F:AJAX渲染&GT;通过与其中不工作;复合材料:clientBehavior&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-31 00:51