<< Previous | Home

Why did I move my blog

Some people might be wondering why I moved my blog? Well, the tricky part about blogging, JUG visits or presentations is making sure people understand what and what is not official.

Since joining Oracle as an employee sometimes people have a tendency to think that I am an official spokesperson and/or a fulltime evangelist. Far from it, I am an engineer tasked with the responsbility of maintaining and furthering Mojarra and Ozark. Both very rewarding to work on. When I do blog, visit JUGs or do presentations I do it to meet all of you. Will I be the perfect presenter? Far from it! After all my job is being an engineer!

Do I welcome feedback? Sure, leave a comment here, or email me directly. Note giving feedback Indirectly will always be ignored.

So to make it 100% clear my blog is my own and presents my personal view points.

Enjoy!

 

And we have moved

And we have moved!

JSF Tip #7 - The RequiredValidator

Say you want to make sure that a value is required.

 <html xmlns:h="http://java.sun.com/jsf/html"  xmlns:f="http://java.sun.com/jsf/core">
  <h:inputText value="#{user.firstName}">
   <f:validateRequired/>
  </h:inputText>
</html>

If you want to disable the RequiredValidator on a page you can mark the validator as disabled as follows:

 <html xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
  <h:inputText value="#{user.firstName}">
   <f:validateRequired disabled="true" />
  </h:inputText>
</html>

If you keep an instance of a RequiredValidator around in your managed bean you can also use binding to bind that particular instance of the RequiredValidator to the tag on the page like so:

 <html xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
  <h:inputText value="#{user.firstName}">
   <f:validateRequired binding="#{settings.requiredValidator}" />
  </h:inputText>
</html>

And a managed bean that has a method similar to the one below:

 public RequiredValidator getRequiredValidator() {
  return requiredValidator;
}

If you specifically want to attach the validator to a specific component then you can use the 'for' attribute to target it. Note this attribute is really helpful when using composite components. Eg.

 <html xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
  <h:inputText id="myinput" value="#{donation.amount}">
   <f:validateRequired binding="#{settings.firstNameValidator}" for="myinput"/>
  </h:inputText>
</html>