-
1. Re: Wanted - a4j:commandButton conditional action solution.
ufonaut May 10, 2010 7:37 PM (in response to karlkras)You can't do anything else in the action parameter; That has to be a straight call to a backing bean. In particular, it certainly does NOT take javascript.
So, you have two options:
1) Don't have an action, and instead whack it all into your onclick. You can't call the backing bean directly as in your "something like this"; Instead you'd have to bring in "a4j:jsFunction"s for the job.
Having one component serve multiple functions is asking for trouble, and will get real messy real fast
Not recommended.
2) Much better is to simply have multiple buttons, and only render those that are applicable - eg:
<a4j:commandButton value="Yes" ajaxSingle="true" action="#{mybean.mainmenu}"
rendered="#{not mainbean.isMainMenu}"
oncomplete="#{rich:component('cancelPanel')}.hide();"
reRender="table" /><a4j:commandButton value="Logout" ajaxSingle="true" action="#{mainbean.logout}" immediate="true"
rendered="#{mainbean.isMainMenu}"oncomplete="#{rich:component('cancelPanel')}.hide();"
/> -
2. Re: Wanted - a4j:commandButton conditional action solution.
ufonaut May 10, 2010 7:48 PM (in response to karlkras)1 of 1 people found this helpfulEven though I don't recommend the first option, here's an example - sometimes it does serve a purpose (eg. to wrap some alerts around the call while dubugging, etc).
So your example would become:
<a4j:jsFunction name="showMainmenu" action="{mybean.mainmenu}"/>
<a4j:jsFunction name="doLogout" action="{authbean.logout}"/>
<a4j:commandButton value="Yes" ajaxSingle="true"
onclick="if (myBean.mainMenu() == true) showMainmenu() else doLogout()l"
oncomplete="#{rich:component('cancelPanel')}.hide();"
reRender="table" />But again - I'd REALLY recommend separate buttons!
-
3. Re: Wanted - a4j:commandButton conditional action solution.
karlkras May 10, 2010 11:25 PM (in response to ufonaut)(edit: I didn't see your 2nd post until after I wrote this... that might be a better solution given this situation)
Hey Rob,
Problem is, both buttons are required to be available on the page at the same time. e.g., there is a Cancel button (which when selected is required to return to the main menu page), and a logoff button (which when selected returns to the logon page) and I want to provide a like confirmation message for both since in both cases all changes up to that point will be lost if the event proceeds.
Is there functionality available for me to make this context switch for the backing bean and perform the action routine from the javacode? e.g., have a method mybean.doCancelProcess which keys off of a state set when one or the other button is clicked?
thanks,
Karl
-
4. Re: Wanted - a4j:commandButton conditional action solution.
ilya_shaikovsky May 11, 2010 5:07 AM (in response to karlkras)1 of 1 people found this helpfulI guess this series of articles will be helpfull
-
5. Re: Wanted - a4j:commandButton conditional action solution.
karlkras May 11, 2010 12:10 PM (in response to ilya_shaikovsky)Hi Ilya,
Well, not surprisingly, this article is where I started, but still the same problem.
Fundamentally at issue is that it's the confirmation dialog that issues the action, not the calling client. Most "traditional" such dialogs are normally a simple mechanism for returning true or false depending on what the user chooses and the client who initiated the confirmation dialog has the logic on what to do with the response.
This not only handles the action, but it hardcodes the action, expecting all clients wanting confirmation services to do the same thing. So I guess my task is, as the author did in handling the client id, figure out how to make this a dynamic bit in the calling client of the facet.
-
6. Re: Wanted - a4j:commandButton conditional action solution.
karlkras May 11, 2010 1:38 PM (in response to karlkras)Oh, maybe not. While this example is very similar to what I had originally worked from it does appear to be fundamentally different. Thanks!
-
7. Re: Wanted - a4j:commandButton conditional action solution.
karlkras May 11, 2010 3:24 PM (in response to karlkras)just realized how painful it is continuing to use antiquated JSF 1.2 libraries. I gotta get this company to port up to a more usable plateform.