简体   繁体   English

通过 <a4j:ajax … /> 渲染组件外部元素

[英]Passing <a4j:ajax … /> render on component external elements

We have build the following composite component, however we haven't found a way to make it rerender component external elements. 我们已经构建了以下复合组件,但是还没有找到一种使它重新呈现组件外部元素的方法。

 <h:panelGroup id="#{cc.attrs.id}Cmtp" rendered="#{cc.attrs.rendered}">
      <div id="#{cc.attrs.id}" class="xyz-select #{cc.attrs.styleClass}" >
        <h:inputText id="input" disabled="#{cc.attrs.disabled}"
          value="#{cc.attrs.value}"
          tabindex="#{cc.attrs.tabindex}" maxlength="#{cc.attrs.maxlength}" 
          converter="#{cc.attrs.converter}">
          <a4j:ajax event="change" render="select" />        
        </h:inputText>
        <rich:select disabled="#{cc.attrs.disabled}"
          id="select" value="#{cc.attrs.value}"
          listWidth="#{cc.attrs.listWidth}"
          converter="#{cc.attrs.converter}">          
          <f:selectItems value="#{cc.attrs.items}" var="xyz"
            itemValue="#{xyz}" itemLabel="#{xyz.name}" />
          <a4j:ajax event="selectitem" render="input" />            
        </rich:select>
        </div>        
      </h:panelGroup>

I have tried adding an attribute defining the external elements to rerender however this just comes up with an error message that the ids are not within the scope of the component. 我尝试添加一个属性来定义要重新渲染的外部元​​素,但是这只是出现一条错误消息,即id不在组件的范围内。

Composite component: 复合组件:

<a4j:ajax event="change" render="select #{cc.attrs.render}" />  

Def: Def:

<xyz:selct ... render="idA idB" />

I have also tried to pass an to it, by exposing the clientBehavior in the interface. 我还尝试通过在接口中公开clientBehavior来将其传递给它。

Composite component Interface: 复合组件接口:

<composite:clientBehavior name="change" event="action" /> 

Def: Def:

<xyz:select ..>
   <a4j:ajax event="change" rerender="idA idB" />
</xyz:select>

However this just stops all the ajax functionality of the component. 但是,这只是停止了该组件的所有ajax功能。

After the suggestion from BalusC (thank you) I have tried the following: 根据BalusC的建议(谢谢),我尝试了以下方法:

<composite:interface>
...
<composite:clientBehavior name="change" event="action" targets="input select"/>  
</composite:interface>

And tried passing it the following AJAX Tag: 并尝试传递以下AJAX标签:

<a4j:ajax event="change" render="idA idB" oncomplete="alert('tada');" />

Sadly none of the specified actions are performed. 遗憾的是,没有执行任何指定的动作。

Relative client IDs (ie not starting with : ) are resolved relative to the current parent NamingContainer component (eg <h:form> , <h:dataTable> , <cc:implementation> , etc). 相对客户端ID(即不是以:开头)是相对于当前NamingContainer组件(例如<h:form><h:dataTable><cc:implementation>等)解析的。

So, in case of the following line inside your composite, 因此,如果您的复合材料中包含以下行,

<a4j:ajax event="change" render="select #{cc.attrs.render}" />  

it's been is searched relative to the <cc:implementation> . 相对于<cc:implementation> However, there's no component with ID idA nor idB inside the <cc:implementation> . 但是, <cc:implementation>没有ID为idAidB组件。

You need to specify an absolute client ID instead. 您需要指定一个绝对客户端ID。 Eg 例如

<xyz:selct ... render=":formId:idA :formId:idB" />

See also: 也可以看看:


As to the <cc:clientBahavior> fail, the context/SSCCE is missing, but I believe it's simply because you forgot execute attribute and mistyped render attribute. 至于<cc:clientBahavior>失败,上下文/ SSCCE丢失了,但是我相信这仅仅是因为您忘记了execute属性和错误键入的render属性。

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

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