aspose file tools*
The moose likes JSF and the fly likes Issue with intermediate posting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Issue with intermediate posting" Watch "Issue with intermediate posting" New topic
Author

Issue with intermediate posting

Chandan Rajan
Greenhorn

Joined: Apr 25, 2008
Posts: 10
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

Joined: Jun 25, 2001
Posts: 16134
    
  21

I think this sounds like a job for AJAX. RichFaces is pretty good for what you want, if I'm reading this properly.


Customer surveys are for companies who didn't pay proper attention to begin with.
Cindy Smith
Greenhorn

Joined: Nov 26, 2007
Posts: 18
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

Joined: Apr 25, 2008
Posts: 10
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue with intermediate posting