I have a problem and I am pretty new for primefaces and JSF altogether, probably it is my lack of knowledge, but I couldn’t find an answer yet, I have XHTML-s, on the main one I have several buttons, and I wrote one feedback dialog which tells that the operation successful, and the name of operation.
The dialog appears, looks fine, but the message is always what I specified on the last button.
Perhaps I misunderstood something with the concept, can anybody help me what am I doing wrong?
here are the code:
Bean
@ManagedBean
@ViewScoped
public class ActionSuccessController extends AbstractAction implements
Serializable {
public String setParam(String actionName) {
ResourceBundle messageBundle = ResourceBundle
.getBundle("hu.avhga.web.partner.messages");
description = messageBundle.getString("actionSuccess");
this.actionName = actionName;
return "";
}
...
Main XHTML where I have the buttons
...
<p:commandButton id="lock"
value="#{msg['PartnerAdmin.button.lock']}"
action="#{partnerAccountAdminAction.lock}"
update=":partnerAccountAdminForm :actionSuccessForm"
disabled="#{partnerAccountAdminAction.disabledButtonMap.get('LOCK')}"
rendered="#{partnerAccountAdminAction.passwordAdmin}"
styleClass="gold"
onclick="#{actionSuccessController.setParam(msg['PartnerAdmin.button.lock'])}"
oncomplete="usersTableWidget.filter();actionSuccessDialogVar.show();"/>
<p:commandButton id="unlock"
value="#{msg['PartnerAdmin.button.unlock']}"
action="#{partnerAccountAdminAction.unlock}"
update=":partnerAccountAdminForm :actionSuccessForm"
disabled="#{partnerAccountAdminAction.disabledButtonMap.get('UNLOCK')}"
rendered="#{partnerAccountAdminAction.passwordAdmin}"
styleClass="gold"
onclick="#{actionSuccessController.setParam(msg['PartnerAdmin.button.unlock'])}"
oncomplete="usersTableWidget.filter();actionSuccessDialogVar.show();"/>
<p:commandButton id="suspend"
value="#{msg['PartnerAdmin.button.suspend']}"
action="#{partnerAccountAdminAction.suspend}"
update=":partnerAccountAdminForm :actionSuccessForm"
disabled="#{partnerAccountAdminAction.disabledButtonMap.get('SUSPEND')}"
rendered="#{partnerAccountAdminAction.userAdmin}"
styleClass="gold"
onclick="#{actionSuccessController.setParam(msg['PartnerAdmin.button.suspend'])}"
oncomplete="usersTableWidget.filter();actionSuccessDialogVar.show();"/>
<p:commandButton id="remove"
value="#{msg['PartnerAdmin.button.remove']}"
action="#{partnerAccountAdminAction.remove}"
update=":partnerAccountAdminForm :actionSuccessForm"
disabled="#{partnerAccountAdminAction.disabledButtonMap.get('REMOVE')}"
rendered="#{partnerAccountAdminAction.userAdmin}"
styleClass="gold"
onclick="#{actionSuccessController.setParam(msg['PartnerAdmin.button.remove'])}"
oncomplete="usersTableWidget.filter();actionSuccessDialogVar.show();"/>
...
After this I have the import of the following XHTML:
<p:dialog id="actionSuccessDialogId" header="#{actionSuccessController.actionName}"
styleClass="dialog" closable="false"
widgetVar="actionSuccessDialogVar" modal="true" appendToBody="true" dynamic="true"
resizable="false" showEffect="fade" hideEffect="explode">
<h:form id="actionSuccessForm" style="text-align:center;">
<h:outputText value="#{actionSuccessController.description}" />
<br />
<br />
<p:commandButton id="okButtonId" value="#{msg['Common.ok']}"
onclick="actionSuccessDialogVar.hide()"
type="button" />
</h:form>
</p:dialog>
I am sure that these “setParam”s run always and for me it seems without reason.
So again the question why I always get the name of “remove” property. Is it because of ajax? Or because these all run when I click somewhere? I am a bit confused. Thanks in advance!
In a nutshell, onclick can’t call a setter like that. What you seem to want is to pass a parameter to your bean action, right? In that case, you want to use the f:setPropertyActionListener tag. So your button would look like this:
The f:setPropertyActionListener invokes the setter specified in the target with the value specified in the value attribute.