Ok, here's a possible solution for you. I've done something similar (in
terms of executing other actions without actually clicking the command
link or button). 

You have 3 buttons, make them a4j:commandButton components.

Give them ids like button1, button2, button3

I'll assume you have 3 action methods like 
#{bean.action1},#{bean.action2},#{bean.action3}

In the reRender attribute put in all 3 button ids and whatever else you
want a4j to reRender. If you want to disable the button after it's
clicked set the rendered attribute to some boolean on a backing bean and
set it to false. So #{bean.action1} should set a boolean like
disableButton1 to false and when it gets reRendered it will be disabled.

Now you want to execute button2 so you can do this by javascript. All
a4j components have an attribute called oncomplete. So in there you need
to do a document.getElementById('button2'). Now that probably won't work
directly since you have naming containers, so button2 will be something
like "yourform:button2". There are other ways to get the element but the
simplest would be to figure out its' full path. I'll assume you
understand how naming containers work. So once you have the element call
its' onclick, this should simulate actually clicking and execute the
action. So really your oncomplete should just call a JS function like
"executeAction(id)"

function executeAction(id) {
  var actionEle = document.getElementById(id);
  if (actionEle) actionEle.onclick();
  else alert('couldn\'t find the element');
}

Your page should look like
<h:form id="someform">

  <t:div id="content">
  <%-- Your page contents here to be rerendered --%>
  </t:div>

  <a4j:commandButton id="button1" action="#{bean.action1}"
      value="Button 1" reRender="button1,button2,button3,content"
      oncomplete="executeAction('someform:button2')"/>

  <a4j:commandButton id="button2" action="#{bean.action2}"
      value="Button 2" reRender="button1,button2,button3,content "
      oncomplete="executeAction('someform:button3')"/>

  <a4j:commandButton id="button3" action="#{bean.action3}"
      value="Button 3" reRender="button1,button2,button3,content "/>

</h:form>

I haven't actually tested this but it should work. Hope it helps.

Matt
-----Original Message-----
From: pharish2 [mailto:phari...@gmail.com] 
Sent: mardi 27 janvier 2009 19:02
To: users@myfaces.apache.org
Subject: Re: execute multiple buttons in jsf one after the other


I tried using ajax, the problem is it not executing synchronously with
backing bean, it will hit the bean and come back, does not wait for the
response or it is not executing accordingly. I am not sure may b jsf is
not
supporting ajax feature fully. I have configured my application for
richfaces which has ajax4jsf. it did not help me. Can you please help me
regarding it.

Thanks
Harish
-- 
View this message in context:
http://www.nabble.com/execute-multiple-buttons-in-jsf-one-after-the-othe
r-tp21580777p21690850.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.

Reply via email to