The Imixs Web-Tools providing a set of business components which can be integrated easily in any modern JSF based Web application. This makes it easy to develop workflow forms in a fast and easy way where the users input can be fully controlled by the Imixs Workflow.
But if you are building complex JSF Forms with a lot of different input fields you may use often the jsf attribute ‘required=true’ to indicate that a input is expected for a specific field.
<h:inputText id="partnumber" value="#{workitemBean.item['txtPartNumber']}" required="true"></h:inputText>
This is a common way to validate the user input. But you can run into a problem if you need some extra actionListeners to update some data in your form independent from the users input.
For Example you have an input field where the user enters a customer id and you want to allow the user to lookup the customers address data with an extra command link bounded to an actionListener. So you will have a code like this:
<h:inputText value="#{workitemBean.item['txtCustomerID']}"></h:inputText> <h:commandLink actionListener="#{workitemBean.doRefreshCustomer}"> <h:graphicImage style="border:0;" url="/layout/icons/check.gif" /> </h:commandLink>
Now in this case the actionListener workitemBean.doRefreshCustomer will not be executed because the input field for the partNumber will be validated first. Even if you add the tag “immediate=true” the actionListener will not work because in this case no data will be available in the actionListener method.
You can solve this problem with a simple trick providing an additional form param indicating if inputFields should be validated or not. You can add an additional param to any commandLink bounded to an actionListener like shown the following example:
<h:inputText value="#{workitemBean.item['txtCustomerID']}"></h:inputText> <h:commandLink actionListener="#{workitemBean.doRefreshCustomer}"> <h:graphicImage style="border:0;" url="/layout/icons/check.gif" /> <f:param name="skipvalidation" value="1" /> </h:commandLink>
Now every time the user clicks the doRefresCustomer command link an additional param named ‘skipvalidation’ with the value ‘1’ will be provided. And now you can use this param to test if your inputFields should be validated or not:
<h:inputText id="partnumber" value="#{workitemBean.item['txtPartNumber']}" required="#{empty param['skipvalidation']}"></h:inputText>
The param ‘skipvalidation’ will only be provided by those commandLinks you need to skip the validation. So you don’t need to change any of your general command buttons where the user input should still be validated by the JSF Framework.
Sweeet! Thanks for that.