Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Saving an h: inputText 2 times  RSS feed

 
Richard Teran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,,,,, I hope this finds you well ..

Sorry to bother. But I'm a bit new to jsf,
and would like to help me with a problem I have

the problem is the following

Want to save the value from h: inputText ... 2 times just click save I will save 2 times the same value ..


would be something like:

<h:inputText value="#{vistaGuardar.valorguardar}" />

the input text that save me 2 times

<a4j:commandButton actionListener="#{vistaGuardar.insertarValor2veces }" value="Save" />



I hope you can help me ..
Thanks for your time .....
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If what you mean is that the "setValorguardar" method is being invoked multiple times from 1 submit request, that is normal. JSF can invoked a property's set/get methods many times in the process of handling a request/response cycle. I've seen 5 or 6 in some cases.

What is important is not how many times the get or set methods are invoked as it is that they should be idempotent. That is, they should not have side-effects that change if the method is invoked more than once nor should they perform long-running actions (since that will drag down performance doing redundant work).

This is why JSF has action methods. So that we're not forced to do our business and database logic in the property methods, but instead do them when a commandButton or commandLink is clicked. The action methods do only get invoked once.

I do not recommend using actionListeners, however. The have their (rare) uses, but a straight (POJO) action method is cleaner and makes for code that's easier to reuse and to debug.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!