开发者

JSF composite component validation

I want to create composite component and attach some validators to it's children, but I want message from validation to be attached to composite component, not to it's child.

In the page using the composite component I want something like this:

<zzz:mycomponent id="my" />
<h:message for="my" />

Now it doesn't work, because message is for component's child, not composite component itself. How to make it for whole component?

Or even better, I would like to add validator to composite component, like:

<zzz:mycomponent id="my" validator="#{bean.vali开发者_高级运维dateComposite}" />

And receiver something like booleans array as value, because inside composite component there are h:selectBooleanCheckbox elements. Is that possible?


Maybe very late to respond on this question but this is how I should do it:

<zzz:mycomponent id="my">
   <f:event type="postValidate" listener="#{bean.doValidation}"/>
</zzz:mycomponent>

The doValidation is then called after the validation of the childs in the 'container'. The method llooks like this:

public void doValidation(ComponentSystemEvent event) {
    ...
}

And you have 2 options in that method:

  • Access the child components (event.getComponent().getChildren() ) and do whatever you want to do with the values submitted on those childs.

  • Or loop over the FacesMessages and reallocate the clientId so that they are placed on your container component (id = my)


You have to put the next code inside your composite definition

      <cc:interface>
          .....
          <cc:editableValueHolder name="attName" targets="Idcomponent" /><!--It allows to acces to the composite-->
          <cc:facet name="textMessage"/>                                 <!--Define the Facet-->
      </cc:interface>
      <cc:implementation id="#{cc.attrs.id}" >
          ......
          <h:inputText id="Idcomponent" value="#{cc.attrs.value}" required="#{cc.attrs.required}"/>
          <cc:renderFacet name="textMessage"/>
      </cc:implementation>

You can use in the JSF page

      <zzz:textBox id="txbTest" label="#{}" value="#{}" >
           <f:validateLongRange for="attName" minimum="-10" maximum="10"/>
           <f:facet name="textMessage">
                <h:message for="value" style="color: blue"/>
            </f:facet>
      </zzz:textBox>

Or another option could be :

      <zzz:textBox id="txbTest" label="#{}" value="#{}" validator="#{bean.yourValidateMethod}" >
           <f:facet name="textMessage">
                <h:message for="value" style="color: blue"/>
            </f:facet>
      </zzz:textBox>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜