Using validator with a variable attribute in ui:repeat

This is indeed specified/expected behavior. The attributes of taghandlers like <f:validateXxx> are evaluated during view build time. So they can’t refer a variable which is only available during view render time like the currently iterated variable of <ui:repeat>. It would indeed work when you use an iterator which runs during view build time like JSTL … Read more

How to trigger args.validationFailed in PrimeFaces oncomplete

If utilizing the JSF-builtin validation facility (i.e. just use validators which throw ValidatorException the usual way with therein the desired faces message) is really not an option for some reason (I’d really think twice, no, thrice about working around JSF validation facility), then you can always use FacesContext#validationFailed() to signal JSF that the validation has … Read more

How to display dialog only on complete of a successful form submit

The PrimeFaces ajax response puts an args object in the JS scope which has a validationFailed property. You could just check for that in the oncomplete. <p:commandButton … oncomplete=”if (args &amp;&amp; !args.validationFailed)” /> If you’re performing validation in action method instead of in a normal validator, and you can’t rework that, then you need … Read more

Change the default message “Validation Error: Value is required” to just “Value is required”

Either use the input component’s requiredMessage attribute: <x:inputXxx … required=”true” requiredMessage=”Value is required” /> Or create a properties file in the classpath which contains the custom message template: javax.faces.component.UIInput.REQUIRED = Value is required. and is been registered as message bundle in faces-config.xml: <application> <message-bundle>com.example.CustomMessages</message-bundle> </application> The above example assumes that the file name is … Read more

Custom model validation of dependent properties using Data Annotations

MVC2 comes with a sample “PropertiesMustMatchAttribute” that shows how to get DataAnnotations to work for you and it should work in both .NET 3.5 and .NET 4.0. That sample code looks like this: [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] public sealed class PropertiesMustMatchAttribute : ValidationAttribute { private const string _defaultErrorMessage = “‘{0}’ and ‘{1}’ … Read more