• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Issue with intermediate posting

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 28070
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Climb the rope! CLIMB THE ROPE! You too tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic