I haven't found the JSF keyword (if one exists) that will tell a field to
use an alternate style if the field is in error.
Here is an example of applying a custom class to a JSF field in error:
JSF view code:
<h:inputText id="name" size="45" value="#{CompanyCtl.curCompany.name}"
required="true" styleClass="input"/>
<h:message for="name" styleClass="error"/>
<h:commandButton value="SAVE" action="#{CompanyCtl.addCompany}"
styleClass="button"/>
JSF controller logic code:
public String addCompany() {
boolean errors = false;
if (Company.exists(new Integer(0), curCompany.getName())) {
UIHelper.addMessage("name", "The name specified has already been
used.");
errors = true;
}
if (errors)
return null;
try {
DBConn.sess().saveOrUpdate(curCompany);
} catch (HibernateException e) {
e.printStackTrace();
return null;
}
return "success";
}
As you can see I have a little bit of leaky abstraction with Hibernate
concerning my ORM layer not being ORM agnostic - oops :-)
The issue I had is that JSF will do the built in validations first and if
any of them fail it will exit the JSF lifecycle and send a response back to
the screenbefore it gets to your business logic edits. This was enough to
make me not use "the validation framework" unless the validations were
incredibly simple. These are the types of "bummers" that bite you in the
butt 3 months after you have made the decision to go with a framework and
are the same types of "bummers" I am watching out for in EGL. Not that I
won't choose EGL for some project eventually, it would just be great to not
learn the hard way.
Aaron Bartell
http://mowyourlawn.com
As an Amazon Associate we earn from qualifying purchases.