开发者

cross field validation for composite components

How do I implement cross-field validation for composite components? The composite component I am using is 开发者_运维问答an input text box (one for email and the second one for confirm email). I applied f:validator tag for the confirmEmail component. How to obtain the value for email composite component in the validate method. Is it UIComponent or UINamingContainer?


Technically, your composite is a UINamingcontainer, but any component can find its children.

I suspect something like the following should work

public void validate(FacesContext context, UIComponent component, Object value) {
    UIInput first = (UIInput)component.findComponent("compositesFirstInputID");
    UIInput second = (UIInput)component.findComponent("compositessecondInputID");

    Object firstEntry = first.getSubmittedValue();
    Object secondEntry = second.getSubmittedValue();
    if(!firstEntry.equals(secondEntry))
        throw new ValidatorException(...);
}

Might want to add some null checking, possibly trim() and use equlasIgnoreCase.


I have implemented the validate method as discussed above. I think the problem with my code is where to use the f:validate tag on composite component.

<eg:inputText id="confirmEmail" value="backingbean.email"/>

<eg:inputText id="email" value="backingbean.email">
<f:validator validatorId="core.jsf.CompareValidator" for="inputText"/>
</eg:inputText>

But when I submit the form the validator is not being called. Should I wrap the validator around the component or is this the correct way of implementing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜