• Post Reply Bookmark Topic Watch Topic
  • New Topic

<t:selectManyCheckbox> valueChangeListener

 
Fabian Angy
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !

I have a problem with a listener in my <t:selectManyCheckbox>. I want to execute my method "processValueChange" when I click on a checkbox but it doesn't work. It's executed only when I click on a button in my screen. Can anybody explain that ?





Thanks in advance.

Angy
 
Fabian Angy
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem solved !

I forgot
 
Fabian Angy
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's strange... on FireFox or Chrome, everything works but on Internet Explorer, there is a problem.
If I want to execute "processValueChange", I have to click on 2 checkboxes because if I click on 1 checkbox, the method is not executed. I don't understand x_X




Angy
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Input controls do not fire events on the server. Only submit controls (buttons, and commandLinks) do that. JSF is based on the idea that the entire HTML form will be submitted, validated and (if valid) processed on a single submit. You can narrow that down using AJAX, but the default mode is submit the entire form/update the entire page.

Rather than use javascript to "push the button", you should code an a4j:support tag for the selectManyCheckbox control and let it do the submit for you by firing for the onclick event.

Note that I'm assuming you're using RichFaces 3.x. RichFaces 4 replaces a4j:support with the JSF standard f:ajax tag and instead of listening for event="onclick", that tag listens for "click".
 
Fabian Angy
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you ! But I have the same problem with IE and <a4j:support>. I have to click twice to execute the method.. :/
For example: 1 click on the checkbox and 1 click on another checkbox or somewhere else on the screen. very very strange !
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Have you removed the JavaScript code and use only a4j:support? Otherwise the JavaScript may be interfering.

2. Are you bound to the onchange event or to the onclick event? The onchange event is notoriously quirky and not just for checkboxes. It also gives problems when used on radio buttons.
 
Fabian Angy
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouhou ! Thank you very much !
I used "onchange" but now I'm using "onclick" and it works !

Thank you !
 
Fabian Angy
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem again... :p

I'm using the listener to know if I have at least one checkbox selected.
Example:


When I click on a button that used "myVariable", my method "processValueChanged" is called and I don't know why, there is no listener on this button. :/
Anybody know why ?

I have another question, what is beter is this case ? A "valueChangeListener" in the <t:selectManyCheckBox> or a "actionListener" in my <a4j:support> ?




BUT, if I use the first option, I have to use an ActionEvent and I don't know how can I see the size of my list of checkboxes... (as the ValueChangeEvent.getNewValue()).

I'm a little bit lost :-)

Can anybody help me ?

Thank you !



">
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you attach an a4j:support to the onclick event and supply it with an action method you do not need any listeners at all.

That is because the action method will ONLY fire if a value has changed. The action method can then examine the checkBoxesListParentSelectedValues property to get the current state of each of the checkboxes. The name "checkBoxesListParentSelectedValues" incorrect. The value of the selectManyCheckbox control is the values of ALL off the checkboxes, not just the selected ones. So a more appropriate name would be "checkBoxesList".

You almost never need an actionListener. An ordinary action method does almost exactly the same thing and it is a lot more POJO-friendly.
 
Fabian Angy
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahhhhh ok !! I didn't know ! Sorry ! :-)
I'll try that tuesday when I'll be at work.

Thank you !
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!