• Post Reply Bookmark Topic Watch Topic
  • New Topic

ActionListener does not work.  RSS feed

 
Salz sack
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I tried to make an ActionListener with JSF 1.2.

If I click on the Button, the new text schould be displayed in the OutputLabel. When I click the button, the ActionListener is called and finds the correct component OutputLabel.
But the problem is, that the new value is not displayed on the website.





Please help.
 
suresh dasari
Ranch Hand
Posts: 121
Chrome Eclipse IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Salz,

your code is perfect and it is working as it is. If you want to see the change you made in the backing bean, you need to rerender that specific component(here outputlable). Use a4j components to implement the functionality of rerendering a component on the fly.
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't see anything wrong with the implementation from a casual look at the View and Model definition, as far as that goes.

However, I can fault the overall design. Listeners are over-used. I think a lot of that is because they were there before newer, better ways of doing things were invented and there's a lot of stale docs around.

While listeners do have their uses, the POJO method is preferable. It allows the app to be created without a lot of JSF-only code, and it reduces the coupling between Model and View. Your listener is required to know intimate details about not only JSF, but also the internal View Component structure. A POJO-equivalent design would only need to know 2 things: 1) when the button was clicked and 2) what the new label to display is.

Re-rendering is another matter. Normally, if the inputs are all valid, the action will fire and the next view displayed will be the one designated by the navigation rule. If you don't provide a rule or provide an invalid one, the current page will be re-displayed, but with the current backing data value (meaning the update label). As Suresh pointed out, you can also use AJAX to re-render only the parts of the page that have changed.
 
Salz sack
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

thanks for your answers. I'll try it with the a4j components.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!