【问题标题】:How to call multiple backing bean methods in JSF 1.2?如何在 JSF 1.2 中调用多个支持 bean 方法?
【发布时间】:2012-04-05 13:24:06
【问题描述】:

有没有办法从 JSF 中的 backing bean 调用多个方法?

我有这样的事情:

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

当用户单击 outputLink 时,我想从 Bean 执行一些其他方法。有可能吗?

PS 我使用的是 JSF 1.2

【问题讨论】:

  • 为什么不使用 actionListener ,例如 public void someMethod(ActionEvent event){ }
  • @Daniel:此属性在 outputlink 中不可用。
  • 我的错...以为是命令链接... :)

标签: jsf call javabeans


【解决方案1】:

将其替换为&lt;h:commandLink&gt;

例如

<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());
}

【讨论】:

    【解决方案2】:

    您为什么不想从您在 bean 中调用的方法中调用该方法?

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 2011-03-13
      • 1970-01-01
      • 1970-01-01
      • 2012-08-03
      • 2019-10-03
      • 2012-11-18
      相关资源
      最近更新 更多