2012-04-05 65 views
0

有沒有辦法從JSF中的支持bean調用多個方法?如何在JSF 1.2中調用多個支持bean方法?

我有這樣的事情:

   <h:outputLink value="#{bean.selectedEntry.link}"> 
        <h:graphicImage 
         url="/CMS/button.png" 
         alt="button"></h:graphicImage> 
      </h:outputLink> 

我想從豆執行一些其他方法,當用戶outputLink的點擊。有可能的?

P.S我使用JSF 1.2

+1

你爲什麼不使用的ActionListener,喜歡的公共無效someMethod(ActionEvent event){} – Daniel 2012-04-05 14:57:23

+0

@Daniel:此屬性在outputlink中不可用。 – BalusC 2012-04-05 17:18:22

+0

我的壞...認爲這是commandlink ... :) – Daniel 2012-04-05 19:12:45

回答

1

將其替換爲<h:commandLink>

E.g.

<h:form> 
    <h:commandLink action="#{bean.openLink}"> 
     <h:graphicImage 
      url="/CMS/button.png" 
      alt="button"></h:graphicImage> 
    </h:commandLink> 
</h:form> 

public void openLink() throws IOException { 
    // You can just call any (multiple) Java methods here the usual way. 
    // ... 

    FacesContext.getCurrentInstance().getExternalContext().redirect(selectedEntry.getLink()); 
} 
0

爲什麼你不希望調用方法從你的bean所調用的方法?

如果您正在調用的方法在其他方案中使用,那麼重構您的代碼以分離關注點併爲每個不同的方案提供入口點。

相關問題