• Post Reply Bookmark Topic Watch Topic
  • New Topic

question about inputText, form and submit buttom on page

 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets say I am going to have multiple text fields to input different components like project, devices and channels. These will be included in a form along with a submit button. Now I am pretty sure I will need to bind these text fields to their respective components in the java code through a managed bean. And if I understand correctly this calls the setter methods for these things? The reason I ask is, because I need a certain set of actions to happen when a user hits submit. I have methods written that will add each of these components to a web service to be stored.
So I need the submit button to call more than one method (postMethods), one for project, one for device, and one for channel. So here is my question. Do I need to put a postMethod in each setter method? Or would I combine all the PostMethods into one single comboMethod and then set that method to be called upon a user hitting the submit button (actione="#{submitBean.comboMethod}"?
I hope this is clear, I would have code but I cant really do any where I am.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the user hits submit, a single 'do' action should get called.

The managed bean, with all of the values set, will be passed into the 'do' action method.

From the action method, you can read the various values from the managed bean, and then fire those values off to the various web services that need to be fed.

Can you implement it in this fashion? That's your basic JSF format. Don't do anything in the setter methods. Just use the managed bean after everything has been set already.

-Cameron McKenzie
 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So Ill have the 3 methods to put the data to the web service for each entity, and I will then make a 4th method that has an instance of each of those 3. Bind this to the submit button and we should be good. Sounds simple enough
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll have all sorts of grief if your setter methods have logic in them. For one thing, you don't know how many times they'll get invoked. Best to simply let the setter methods set and the action methods take actions.

If you want to be nice and modular - for example to use off-the-shelf components or create code that's easier to unit-test and reuse separately, one way to get a 3-way handling on an action is to fron the action individual actions with a "master controller" action, as was suggested, and put the master controller action into a session-scope bean that gets the subsidiary beans wired into it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!