jsf 2.0 复合组件 - 如何修改外部 bean/属性
我刚刚学习 JSF 2 并使用简单的自定义组件。 想象一个支持 ajax 的自定义组件,具有两个 inputText 字段:
...
<h:body>
<composite: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>
...
使用该组件的页面如下所示:
...
<h:body>
<h:form>
<dom:domain domId="100" value="#{testCtrl.code}"/>
</h:form>
</h:body>
...
定义 domBean 的类中有趣的方法如下所示:
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
}
我希望 input.setValue(code) 会设置 inputText 值,这是延迟表达式“#{cc.attrs.value}”,它通过“父”页面链接到#{testCtrl.code}。 不幸的是,testCtrl.code 永远不会填充输入的值。
我做错了什么?
谢谢你!
I am just learning JSF 2 and playing with simple custom components.
Imagine an ajax enabled custom component with two inputText fields:
...
<h:body>
<composite: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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,经过几个小时的跟踪,我意识到这是 myfaces 2.0.0 实现中的一个错误。
使用最近的 2.0.1 快照,它可以工作。
有关更多信息,请查看 apache tracker 中的问题:
https://issues.apache.org/jira/browse/MYFACES-2675
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