Skip to content

Instantly share code, notes, and snippets.

@mojavelinux
Created March 1, 2010 22:49
Show Gist options
  • Save mojavelinux/318905 to your computer and use it in GitHub Desktop.
Save mojavelinux/318905 to your computer and use it in GitHub Desktop.
<h:form>
<f:event type="postValidate" listener="#{minMax.validate}"/>
<h:inputText id="min" value="#{bean.min}"
binding="#{minMax.minInput}"/> <h:message for="min"/>
<h:inputText id="max" value="#{bean.max}"
binding="#{minMax.maxInput}"/> <h:message for="max"/>
<h:commandButton value="Submit"/>
</h:form>
public @Model class MinMax {
@Inject FacesContext ctx;
private UIInput minInput, maxInput; // accessors hidden
public void validate() {
if (ctx.isValidationFailed()) { return; }
if ((Integer) maxInput.getValue() < (Integer) minInput.getValue()) {
ctx.addMessage(maxInput.getClientId(ctx),
new FacesMessage("cannot be less than min value"));
ctx.validationFailed();
ctx.renderResponse();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment