ELContext elCtx = FacesContext.getCurrentInstance().getELContext();
MyBean bean = (MyBean) elCtx.getELResolver().getValue(elCtx, null, "myBean");
FacesContext ctx = FacesContext.getCurrentInstance();
PartialResponseWriter writer = ctx.getPartialViewContext().getPartialResponseWriter();
writer.startDocument();
writer.startError(errorName);
writer.write(errorMessage);
writer.endError();
writer.endDocument();
ctx.renderResponse();
ctx.responseComplete();
<h:inputText id="myinput" validator="#{myBean.validateMyInput}"
<h:message for="myinput" />
public void validateMyInput(FacesContext context, UIComponent inputComponent, Object value) {
// ...
if(!valid) {
throw new ValidatorException(new FacesMessage("your message"));
}
}
FacesContext.getCurrentInstance().addMessage("main:password", new FacesMessage("Wrong username or password!"));
FacesContext.class.getPackage().getImplementationVersion();
Source: http://stackoverflow.com/a/13125869/771431
src: url("#{resource['fonts:glyphicons-halflings-regular.eot']}");
Use case: validate required only when pressing "Sumbit" button.
<h:inputText value="#{myBean.myValue}" required="#{param['validateRequired']}" />
<h:commandLink action="#{myBean.submitValue()}">
Sumbit value
<f:param name="validateRequired" value="true" />
</h:commandLink>
$(document).ready(function () {
jsf.ajax.addOnEvent(function (data) {
switch (data.status) {
case "begin":
$('.loading').removeClass('hide');
break;
case "complete":
$('.loading').addClass('hide');
break;
}
});
});