Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with intermediate posting

 
Chandan Rajan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?

TIA,
Chandan
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this sounds like a job for AJAX. RichFaces is pretty good for what you want, if I'm reading this properly.
 
Cindy Smith
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get the �subject� value by binding it to a component on your backing bean even with immediate=true set on the add button.

Try this:
Use the binding property on your "subject" <h:inputText> tag.
binding=�#{yourBean.someUIComponent}�

Add a UIComponent to your backing bean along with getters and setters.
private UIInput someUIComponent;

Now you can call the getSubmittedValue() method on someUIComponent for the subject value entered by the user during the add operation.

Hope this helps.
 
Chandan Rajan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the replies Tim and Cindy.

The project does not have the AJAx sanction yet. So I guess would need to handle it on the server.

Will try Cindy's solution and revert back.

Regards,
Chandan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic