1

我有一个问题,我对 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吗?或者因为当我点击某个地方时这些都会运行?我有点困惑。提前致谢!

4

2 回答 2

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 属性中指定的值调用目标中指定的设置器。

于 2013-01-24T12:44:23.153 回答
0

在 Andre 的大力帮助下,最终的解决方案是:

<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 行并将更新参数更改为“...:actionSuccessDialogId”,因此它适用于整个对话框。

于 2013-01-24T13:42:25.643 回答