【问题标题】:How to call a bean method when page loads?页面加载时如何调用bean方法?
【发布时间】:2015-01-10 15:33:05
【问题描述】:

我想知道在页面加载后我应该如何调用 bean 方法。我尝试过这样的事情,但实际上并没有奏效:

            <p:remoteCommand name="autoRun"
                             action="#{enbBean.getFakeEndListForTesting()}"
                             autoRun="true" update="enbTable"/>

【问题讨论】:

    标签: spring jsf primefaces


    【解决方案1】:

    以下链接访问。据我所知 xhtml 页面加载事件运行!!!

    When to use f:viewAction / preRenderView versus PostConstruct?

    【讨论】:

      【解决方案2】:

      奇怪,应该可以。有什么例外吗? This post 包含一些实现您需要的替代方法。最标准的方式应该是第一个建议,使用

      <h:body>
          <f:ajax event="load" listener="#{bean.onload}" />
      </h:body>
      

      有了这个

      public void onload(AjaxBehaviourEvent event) {
          // ...
      }
      

      【讨论】:

        【解决方案3】:

        你可以为这个方法使用@PostConstruct注解。

        【讨论】:

          猜你喜欢
          • 2019-10-03
          • 1970-01-01
          • 2012-08-03
          • 2019-11-30
          • 1970-01-01
          • 2018-05-21
          • 1970-01-01
          • 1970-01-01
          • 2016-06-26
          相关资源
          最近更新 更多