commandButton fails when disabled=true

UI Components for JSF
Post Reply
dblanco
Posts: 35
Joined: 02 Oct 2015, 09:13

16 Jun 2016, 11:50

Since Primefaces upgrade to 6.0 I have a small problem with a commandButton:

When I put in the commandButton the disabled attribute = true and click on the button once it has been enabled by another event, instead of performing the action configured, it reloads the page and does not perform that action.
PrimeFaces 12.0 | JSF 2.3 | Barcelona Theme 5.0.0

hsntpn
Posts: 15
Joined: 18 Mar 2016, 21:24

17 Jun 2016, 09:02

Can you post your code in here?

dblanco
Posts: 35
Joined: 02 Oct 2015, 09:13

17 Jun 2016, 10:38

Code: Select all


<p:inputText id="globalFilter" widgetVar="globalFilter"
	style="width:150px" placeholder="Buscar...">
	<p:ajax event="keyup" onstart="applyGlobalFilter();" 
		update="toolButtons" global="false"/>								
</p:inputText>
							
<p:commandButton id="resetBtn" widgetVar="resetBtn" disabled="true"
	icon="fa fa-close" styleClass="BottonClearFilter"
	update="globalFilter" oncomplete="applyGlobalFilter();">								
	<p:resetInput target="globalFilter" />
</p:commandButton>

<script type="text/javascript">
	function applyGlobalFilter() {
		if (PF('globalFilter').jq.val().length == 0) {
			PF('tablePF').clearFilters();
			PF('resetBtn').disable();
		} else {
			PF('tablePF').unselectAllRows();
			PF('tablePF').filter();
			PF('resetBtn').enable();										
		}
	}
</script>

The problem is in commandButton "resetBtn" when disable is true.
PrimeFaces 12.0 | JSF 2.3 | Barcelona Theme 5.0.0

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

17 Jun 2016, 11:16

The button disabled state is initially set explicity set to true, this means that its state in the server side component tree will never change and the client rendered button might be enabled but the server side equivalent never will be.
Change the state on the server side and update the button via ajax.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

hsntpn
Posts: 15
Joined: 18 Mar 2016, 21:24

17 Jun 2016, 13:04

Thanks for share your code.You can use onkeyup method in your code.

Code: Select all

 <p:inputText id="inputt" onkeyup="
                    if (this.value.length>0) {
                        PF('resetBtn').enable();
                    } else {
                        PF('resetBtn').disable();
                    }
                         ">

            </p:inputText>


            <p:commandButton id="resetBtn" widgetVar="resetBtn" disabled="true"
                             icon="fa fa-close" styleClass="BottonClearFilter"
                             update="globalFilter" oncomplete="applyGlobalFilter();" value="Button">                        
                <p:resetInput target="globalFilter" />
            </p:commandButton>

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 51 guests