2015-08-30 72 views
1

JSF或PrimeFaces中是否有自動加載命令?自動加載命令

我有我用我的小面一個JSF模板:

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    template="template.xhtml" 
    xmlns:p="http://primefaces.org/ui" 
    xmlns:h="http://xmlns.jcp.org/jsf/html" 
    xmlns:f="http://xmlns.jcp.org/jsf/core"> 

    <h:form> 
     <p:remoteCommand name="onload" action="#{mainMenuBean.setMenuCategories}" autoRun="true" /> 
    </h:form> 

    <ui:define name="west"> 
     <ui:include src="mainmenu.xhtml" /> 
    </ui:define> 

    <ui:define name="center"> 
     <p:outputLabel value="Zentrum" /> 
     <h:form> 
      <p:remoteCommand name="rc" update="msgs" actionListener="#{mainMenuBean.setMenuCategories()}" /> 

      <p:growl id="msgs" showDetail="true" /> 
      <p:commandButton type="button" onclick="rc()" value="Execute" icon="ui-icon-refresh" /> 
     </h:form> 
    </ui:define> 
</ui:composition> 

現在p:remoteCommand不會出於某種原因。是否有命令可以替代p:remoteCommand來在每次加載時自動執行一些bean方法?

+0

在google上搜索'在頁面加載jsf stackoverflow的方法',然後選擇一個您認爲是問題的答案,然後將其標記爲重複或刪除它。 – Kukeltje

+0

謝謝@Kukeltje提供鏈接。這爲這個主題增添了一個非常完整的解釋。關於這個案例,下面的答案几乎完全符合我的要求。總是很好,但有可能進一步細化。再次感謝。 – Socrates

回答

2

JSF 2.2具有viewAction,它可以在每個負載或每個get(並在回發中跳過)上執行。它放置在網頁的元部分:

<f:meta> 
    <f:viewAction action="#{anyBean.anyAction}"/> 
    </f:meta> 

編輯:記住,這是一個動作成分,所以它的執行將取決於前述任一項驗證/轉換是成功的。

+0

非常棒@fdreger!快速回答,現在所有作品。非常感謝! – Socrates

+0

允許搜索重複項。我知道它沒有聲望,但它保持StackOverflow清潔... – Kukeltje