请求JSF页面时,如何在Bean中调用方法? [英] How to call a method in the bean when a JSF page is requested?

查看:97
本文介绍了请求JSF页面时,如何在Bean中调用方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当请求JSF页面时,如何在Bean中调用方法? 示例我有一个JSF页面"MyPage.jsf"和它的后端bean"MyBean",并且它有一个方法"myMethod()". 请求MyPage.jsf时可以调用MyBean.myMethod()吗?

How to call a method in the bean when a JSF page is requested? Example I have a JSF page "MyPage.jsf" and its backend bean "MyBean" and it has a method "myMethod()". Is it possible to call the MyBean.myMethod() when MyPage.jsf is requested?

推荐答案

如果您已将Faces-config.xml中的MyBean作为托管bean添加到了

If you have added MyBean in the faces-config.xml as a managed bean:

<managed-bean>
  <managed-bean-name>myBean</managed-bean-name>
  <managed-bean-class>MyBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

在MyPage.jsf示例中使用Bean时:

When you use the Bean in your MyPage.jsf example:

<h:outputText value="#{myBean.mytext}"/>

将自动调用MyBean的默认构造函数.从默认构造函数执行myMethod().

The default constructor of MyBean will automatically be called. Execute myMethod() from the default constructor.

public MyBean() {
  this.myMethod();
}

它将在页面加载时被调用.

And it will get called on page load.

这篇关于请求JSF页面时,如何在Bean中调用方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆