I have a <h:form> with a "name" <h:inputText>, a "subject" <h:inputText>, a "subjects" <h:selectManyListbox>, a "add" <h:commandButton> and a "save" <h:commandButton>.
The "name" <h:inputText> has the required attribute set to true.
The requirement is 1. the user will enter the name 2. then he will enter a subject name 3. Click on "add" button, now the subject should get added to the "subjects" <h:selectManyListbox>. I have done this by setting the action attribute of the "add" <h:commandButton> to a method. This method reads the property bound to the "subject" <h:inputText> and adds a javax.faces.model.SelectItem to the "subjects" <h:selectManyListbox>. 4. Finally the user clicks save and the action method bound to the save button persists everything on to the db.
Everything is fine. But the issue comes in when the user does not enter the "name" textbox but first fills out the "subject" textbox and clicks "add". Now in the request processing life cycle, JSF finds that the **required** "name" is not provided and hence validation fails and it queues a message. The action method bound to the "add" button is never invoked. So the user sees a "first fill the name" message. This message is not supposed to be rendered now because the user is not still done with the form. He is done only when he clicks on the "save" button. Hence to resolve this validation issue, I set the "immediate" attribute of the "add" <h:commandButton> to "true". Now the action method of "add" <h:commandButton> does get executed. But the property of "subject" <h:inputText> is null because I have now bypassed the property setters by setting the immediate the "true".
Is there a way I can have the "add" <h:commandButton> action method invoked with the properties set even when the "name" <h:inputText> is not filled?