如何在模糊时验证复合组件?

时间:2012-05-02 16:08:28

标签: jsf-2 composite-component

我有一个包含两个inputText组件的复合组件。 复合组件管理包含两个整数的bean。

class valueBean {
  private Integer valueA;
  private Integer valueB;
  //getters, setters.
}

<composite:interface componentType="valueBeanUI">
  <composite:attribute name="value">
</composite:interface>

<composite:implementation>
  <h:inputText id="inputA"/>
  <h:inputText id="inputB"/>
</composite:implementation>

在我的valueBeanUI中,我实现了getConvertedValue和encodeBegin。

一切都按预期工作 - 当我点击提交时,调用getConvertedValue中的代码,如果用户在整数字段中输入字符,我可以抛出错误消息。

我想要做的是能够在两个字段中都要求有效值,并在不满足此条件时显示一条错误消息。当用户点击提交时,我有这个工作,但我想在任一字段(inputA或inputB)的模糊时触发它。当两个字段模糊时,我无法弄清楚如何验证支持组件。谁能建议一种方法来实现这一目标?我不想提交整个表单 - 我想通过ajax来完成这个组件。

1 个答案:

答案 0 :(得分:0)

只需在输入中添加<f:ajax event="blur">即可。

<h:inputText id="inputA">
    <f:ajax event="blur" execute="@this inputB" render="messageForInputA messageForInputB" />
</h:inputText>
<h:inputText id="inputB">
    <f:ajax event="blur" execute="@this inputA" render="messageForInputA messageForInputB" />
</h:inputText>

messageForInputA应指向<h:message id="messageForInputA">

相关问题