-
1. Re: Component control doesn't work when a button is disabled
migore Mar 11, 2013 6:54 PM (in response to migore)My temporaty (hopefully) solution to this:
{code:xml}
<h:commandButton id="delete-all-button" value="#{msgs.geral_excluir_selecionados}"
rendered="#{transacaoBean.dataModel.rowCount != 0}" styleClass="realbtn radius3"
type="button" disabled="true"
onclick="RichFaces.ui.ComponentControl.execute(event,{'selector':null,'target':['pesquisa\u002Dtransacao\u002Dform:confirm\u002Dpopup'] ,'callback':function(event,component){component['show'].apply(component,[event,{'left':(jQuery(window).width()/2)-250,'top':(jQuery(window).height()/2)-150} ] );}} ); return false;">
<rich:componentControl target="confirm-popup" operation="show"></rich:componentControl>
</h:commandButton>
{code}
I need to leave the rich:componentControl so that the proper javascript is imorted by richfaces.
-
2. Re: Component control doesn't work when a button is disabled
lfryc Mar 12, 2013 9:19 AM (in response to migore)Hey Migora,
I belive that no disabled button should actually react on user's click.
It works from point of view of JavaScript - the event can be registered.
But on the other hand, the h:commandButton just won't add a click event handler and decode behaviors (like f:ajax or rich:componentControl) because the button is in it's disabled state.
At least it leads into bad user experience- me as a user won't expect disabled button to open popup.
-
3. Re: Component control doesn't work when a button is disabled
migore Mar 12, 2013 9:26 AM (in response to lfryc)The button is disabled when the page is loaded, after a user action on another component, the button is enabled.
The butotn is disabled on page load, then, when the user select a row in the table of the page to be deleted, the button is activated.
When the button is disabled it doesn't trigger the click event, that is the reason that I'm using it so that the popup can only be opened when there is something to be deleted.
-
4. Re: Component control doesn't work when a button is disabled
bleathem Mar 22, 2013 6:51 PM (in response to migore)To be clear, you are not expecting the component control to be invoked when the button is disabled, but rather, after the button has been enabled. To be more precise, what you expect is:
- Load the page (button is disabled, clicking it does not invoke the component control)
- Some user action triggers the button to become enabled
- Clicking on the button should now invoke the component control
Howver what you observe is that in step 3, the component control is not activated after you enable the button. Is this correct?
Have you tried re-rendering (via f/a4j:ajax) the button after the button becomes enabled? That should cause the component control to be registered.
-
5. Re: Component control doesn't work when a button is disabled
migore Mar 24, 2013 8:26 PM (in response to bleathem)Brian Leathem wrote:
To be clear, you are not expecting the component control to be invoked when the button is disabled, but rather, after the button has been enabled. To be more precise, what you expect is:
- Load the page (button is disabled, clicking it does not invoke the component control)
- Some user action triggers the button to become enabled
- Clicking on the button should now invoke the component control
Howver what you observe is that in step 3, the component control is not activated after you enable the button. Is this correct?
Have you tried re-rendering (via f/a4j:ajax) the button after the button becomes enabled? That should cause the component control to be registered.
Yes, that's correct.
Have you tried re-rendering (via f/a4j:ajax) the button after the button becomes enabled?
No, I haven't, I'm enabling the button through client side JS.
-
6. Re: Component control doesn't work when a button is disabled
bleathem Mar 24, 2013 8:28 PM (in response to migore)Can you try re-rendering (via f/a4j:ajax) the button after the button becomes enabled (or use an ajax call to enable the button)? That should cause the component control to be registered.
-
7. Re: Component control doesn't work when a button is disabled
migore Mar 27, 2013 1:10 PM (in response to bleathem)It works, but I wouldn't like to make a ajax call to do that.
-
8. Re: Component control doesn't work when a button is disabled
bleathem Mar 27, 2013 1:46 PM (in response to migore)Thanks for trying it. It demonstrates that the framework doesn't register event handlers for disabled components. JSF really is a server-side rendering framework, and is not meant to work with client-side manipulations of the render. We would have to expose some sort of client-side-disabled attribute
A workaround for this would be to have the button enabled in the facelet tag, then have some javascript that executes on page load to disable the button. Then later re-enabling the button via javascript would work, as the event handler was registered on page load.
Cheers,
Brian Leathem
-
9. Re: Component control doesn't work when a button is disabled
bleathem Apr 5, 2013 5:45 PM (in response to bleathem)Did the suggested workaround work for you?
A workaround for this would be to have the button enabled in the facelet tag, then have some javascript that executes on page load to disable the button. Then later re-enabling the button via javascript would work, as the event handler was registered on page load.
As I think about it more, this really is teh way to do it. Don't disable a component on the serverside via EL if you want to later enable it with only a client-side interaction. Leave it enabled on the server via EL, and disable it in the client on page load.