Primefaces 5.2,什么时候应该评估/执行menuitem?

时间:2016-11-10 03:34:11

标签: primefaces jsf-2 exec refresh menuitem

我正在使用带有Primefaces 5.2的JSF 2.2来实现我的JSF项目。我尝试通过使用结果访问我的main.xhtml中的支持bean控制器来与menuitem建立链接,例如:

<h:form prependId="false" id="headerForm">
  ......
  <p:menubar >
    <p:submenu label="#{apps['application.staff.myinfo']}" icon="ui-icon-document">
        <p:menuitem value="#{apps['application.staff.myinfo']}" immediate="true" outcome="#{staffControlBean.viewStaff()}" process="@form" update="@all" icon="fa fa-fw fa-leaf"
                    disabled="#{empty loginControlBean.staffSession.username}"/>
        <p:separator />
        <p:menuitem value="Quit" url="#" />
    </p:submenu>
  </p:menubar>
  ......
</h:form>

我的支持bean为:

@Named(value = "staffControlBean")
@SessionScoped
public class StaffControlBean implements Serializable{
  private static final String STAFF_VIEW="/staff/staffView.xhtml";
  ......
  public String viewStaff(){
    logger.info("View staff from menuitem clicked.");
    if(loginControlBean.getStaffSession().isChangePassword()){
        logger.info("password has to be changed before use this services.");
        loginControlBean.fireChangePasswordDialog();
        return "";
    }else {
        return STAFF_VIEW;
    }
  }
  ......
}

从上面的片段中你会看到,我希望当我从菜单栏中点击menuitem时,将调用后端控制器方法viewStaff来返回更改密码对话框或返回我的员工视图。

但不幸的是,每当我访问(或刷新)main.xhtml而没有点击菜单栏中的任何菜单项时,支持bean方法被评估/执行了两次。这是我在服务器上找到的日志:

......
####<Nov 10, 2016 2:02:29 PM AEDT> <Info> <com.longz.ozssc.web.staff.StaffControlBean> <macmini16g.tweedheadstorage.com.au> <OzsscWEBServer> <[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <bc92beef-9f93-4923-a503-9a9cee37010d-00000071> <1478746949108> <[severity-value: 64] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-000000> <View staff from menuitem clicked.> 
####<Nov 10, 2016 2:02:29 PM AEDT> <Info> <com.longz.ozssc.web.staff.StaffControlBean> <macmini16g.tweedheadstorage.com.au> <OzsscWEBServer> <[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <bc92beef-9f93-4923-a503-9a9cee37010d-00000071> <1478746949109> <[severity-value: 64] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-000000> <View staff from menuitem clicked.>    
......

我的问题是:当评估或执行JSF中的链接或按钮时?为什么在加载或刷新页面时始终评估或执行它。我怎么能避免它发生?

欢迎并赞赏任何建议。

0 个答案:

没有答案