Button Action Delay

UI Components for JSF
Post Reply
User avatar
benpad
Posts: 58
Joined: 24 Jun 2010, 04:54
Location: Makati, City Philippines
Contact:

30 Sep 2010, 10:32

Hi.

Is there a way how to delay the action of a button? Let's say I have a form with text boxes and a button inside it. If I clicked the button multiple times (quickly), the button won't wait for the response to send another submit action.

Thanks.
PrimeFaces 2.1
JSF 2.0
GlassFish 3 Server
Mojarra 2.0.2

User avatar
leofigs
Posts: 5
Joined: 14 Sep 2010, 17:19

30 Sep 2010, 10:41

I guess you can disable the button with javascript on the first click if thats the case.

And if it is a ajax button you can try using the p:commandButton onclick and oncomplete to disable and then enable again after response.
------------------------------------------------------------------------------------------
Primefaces 2.2.1 - JSF 2 - Mojarra 2.0.3 - Spring 3.0.3 - Tomcat 6.0.29

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

30 Sep 2010, 11:37

Note that every ajax request is queued, so an ajax request will be sent once the previous one gets it's response.

User avatar
benpad
Posts: 58
Joined: 24 Jun 2010, 04:54
Location: Makati, City Philippines
Contact:

04 Oct 2010, 11:34

Let's say I have this form.

Code: Select all

<h:form>

<h:inputText value="#{myBean.specialValue}"/>
<p:commandButton value="Add" actionListener="#{myBean.addSomething}" />

</h:form>
The addSomething method consist of:

Code: Select all

public void addSomething() {
	myList.add(specialValue);
	
	// Clear the specialValue
	specialValue = "";
}
If you click the button multiple times very quickly, the specialValue gets added multiple times too with the same value. Is there a better way to eliminate the multiple request to the backing bean?

Even if I put specialValue = "", the value is still the same.
PrimeFaces 2.1
JSF 2.0
GlassFish 3 Server
Mojarra 2.0.2

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

04 Oct 2010, 15:10

Hi,

How Cagatay said Ajax request are queued per default - an Ajax request will be sent once the previous one gets it's response. You can show an overlay with a loading indicator as peventation for multiply submittions. Sure, you still can do multiply clicks, but it's a problem of user. He may do it. If specialValue stays the same you add the same value in the addSomething() method. That's so.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

xeo
Posts: 5
Joined: 17 Nov 2010, 22:48

06 Jan 2011, 00:56

Benpad maybe it would be usefull for you...

Code: Select all

<p:commandButton  image="search" widgetVar="buttonSearch" id="buttonSearch" async="true"
                                      actionListener="#{equipoMed.updateListEM}" immediate="true" 
                                      onclick="buttonSearch.disable()" oncomplete="buttonSearch.enable()"
                                      update="buttonSearch ajaxStatus listaEM resultSearch"
                                      value="Generar Lista de Resultados">
                    </p:commandButton>

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 52 guests