简体   繁体   中英

JSF 2 Composite Component doesn't update value with f:ajax

I'm trying to implement a Composite Component in JSF 2, which will support the "change" ajax event. The CC is:

<!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://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:composite="http://java.sun.com/jsf/composite">
<!-- INTERFACE -->
<composite:interface name="inputText">
    <composite:attribute name="label" />
    <composite:attribute name="value" />
    <composite:attribute name="disabled" default="false" />
    <composite:attribute name="required" default="false" />
    <composite:attribute name="rendered" default="true" />
    <composite:clientBehavior name="change" event="change" 
        targets="#{cc.clientId}:input" />
</composite:interface>

<!-- IMPLEMENTATION -->
<composite:implementation>
    <h:panelGroup id="#{cc.clientId}" rendered="#{cc.attrs.rendered}">
        <h:outputLabel value="#{cc.attrs.label}" for="input" />
        <h:inputText id="input" label="#{cc.attrs.label}" 
            value="#{cc.attrs.value}" disabled="#{cc.attrs.disabled}" 
            required="#{cc.attrs.required}" />
        <h:message for="input" />
    </h:panelGroup>
</composite:implementation>
</html>


Now, I'm trying to use it in the following form:

<h:form id="form">
    <input:inputText value="#{bean.value}" label="d1" id="d1">
        <f:ajax event="change" update="@this,d2,d3" />
    </input:inputText>
    <h:inputText value="#{bean.value}" id="d2">
         <f:ajax event="change" update="@this,d1,d3" />
    </h:inputText>
    <h:outputText id="d3" value="#{bean.value}" />
</h:form>

As far as I understand, if I change d1 , d2 and d3 should display the value of d1, and if I change d2 , both d1 and d3 should change accordingly as well.
The problem is that when I change the value in d2 , it only reflects in d3, while d1 stays blank, and when I change d2 , d1 and d2 stays blank.

I'm using Mojarra 2.0.2 (I couldn't manage to make 2.0.3 on Google App Engine, which is my AS). Do I miss something in the way composite components should be built? Or is it a bug in Mojarra 2.0.2?

This:

<h:panelGroup id="#{cc.clientId}"

is incorrect. #{cc.clientId} is the id of your component, which is the parent of that panelGroup. Setting them to have the same ID is incorrect. Give it an id like " myComponentPanel ", and it will have the absolute id (when placed in the component tree) of " #{cc.clientId}:myComponentPanel ".

I suspect if you correct this, your ajax behaviour will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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