我有一个问题,我对Primefaces和JSF来说很新,可能是我缺乏知识,但我找不到答案,我有XHTML-s,主要有我有几个按钮,我写了一个反馈对话框,告诉操作成功,以及操作名称。
对话框出现,看起来很好,但是消息总是我在最后一个按钮上指定的。 也许我误解了这个概念,任何人都可以帮助我,我做错了什么?
这是代码:
豆
@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 "";
}
...
主XHTML我有按钮
...
<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();"/>
...
在此之后我导入了以下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>
我确信这些“setParam”一直在运行,对我来说似乎没有理由。 再次问我为什么总是得到“删除”属性的名称。是因为ajax吗?或者因为当我点击某个地方时这些都会运行?我有点困惑。提前谢谢!
答案 0 :(得分:2)
简而言之,onclick无法像这样调用setter。你似乎想要的是将参数传递给你的bean动作,对吧?在这种情况下,您要使用f:setPropertyActionListener标记。所以你的按钮看起来像这样:
<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"
oncomplete="usersTableWidget.filter();actionSuccessDialogVar.show();">
<f:setPropertyActionListener target="#{actionSuccessController.param}" value="#{msg['PartnerAdmin.button.lock']}" />
</p:commandButton>
f:setPropertyActionListener使用value属性中指定的值调用target中指定的setter。
答案 1 :(得分:0)
在安德烈的帮助下,最终解决方案是:
<p:commandButton id="lock" immediate="true"
value="#{msg['PartnerAdmin.button.lock']}"
action="#{partnerAccountAdminAction.lock}"
update=":partnerAccountAdminForm :actionSuccessDialogId"
disabled="#{partnerAccountAdminAction.disabledButtonMap.get('LOCK')}"
rendered="#{partnerAccountAdminAction.passwordAdmin}"
styleClass="gold"
oncomplete="usersTableWidget.filter();actionSuccessDialogVar.show();">
<f:setPropertyActionListener target="#{actionSuccessController.actionName}" value="#{msg['PartnerAdmin.button.lock']}" />
<f:setPropertyActionListener target="#{actionSuccessController.description}" value="#{msg['PartnerAdmin.button.lock']}"/>
</p:commandButton>
希望它可以帮助遇到类似问题的人。 我添加了两个setproperty行并将update参数更改为“...:actionSuccessDialogId”,因此它适用于整个对话框。