开发者

jsf 2.0 composite components - how to modify outer beans / attributes

开发者 https://www.devze.com 2023-01-01 10:29 出处:网络
I am just learning JSF 2 and playing with simple custom components. Imagine an ajax enabled custom component with two inputText fields:

I am just learning JSF 2 and playing with simple custom components. Imagine an ajax enabled custom component with two inputText fields:

...
<h:body>
  <composi开发者_如何学编程te:interface>
    <composite:attribute name="domId" required="true" />
    <composite:attribute name="value" required="true" />
  </composite:interface>
  <composite:implementation>
    <h:inputText id="code" value="#{cc.attrs.value}">
    <f:valueChangeListener binding="#{domBean}" >    
    </f:valueChangeListener>
      <f:ajax event="valueChange" execute="@this"
      render="name"/>  
    </h:inputText>

        <h:inputText id="name" value="#{domBean.name}" disabled="true">
    </h:inputText>
  </composite:implementation>
...

The page with uses the component looks like the following:

...
<h:body>
  <h:form>
  <dom:domain domId="100" value="#{testCtrl.code}"/>
  </h:form>
</h:body>
...

the interesting method in the class which defines the domBean looks like:

  public void processValueChange(ValueChangeEvent event)
      throws AbortProcessingException
  {
    String code = (String) event.getNewValue();
    UIInput input= (UIInput) event.getSource();
    name = resolveCode(code); //some magic transformation
    if (name != null)
      input.setValue(code); //just want to set the "entered" / "validated" text
   }

I would expect that input.setValue(code) would set the inputText value, which is the deferred expression "#{cc.attrs.value}", which is linked to #{testCtrl.code} by the "parent" page. Unfortunately, testCtrl.code is never populated with the entered value.

What I am doing wrong?

Thank you!


Finally, after hours of tracing, I realized that this is a bug in the myfaces 2.0.0 implementation. Using a recent 2.0.1 snapshot, it works.

For more information, please have a look at the issue in the apache tracker: https://issues.apache.org/jira/browse/MYFACES-2675

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号