2012-04-05 64 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所调用的方法?

如果您正在调用的方法在其他方案中使用,那么重构您的代码以分离关注点并为每个不同的方案提供入口点。

相关问题