0

在我的 JSF 2.0 项目中,我有 2 个类:

public class driver {  
    private String name = "Mr Taxi";  

    public String getName {  
        return name;  
    }  
}  

...

import driver;  
public class CarBean {

    private Driver driver;  
    private String anotherProperty;  

    public String getAnotherProperty {  
        return anotherProperty;  
    }   
}  

和 jsf 文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:body>
        The car has a driver with name: #{carBean.driver.name} <--------Focus on this one

    </h:body>
</html>   

我知道上面的例子不起作用。但是有什么方法可以从 jsf 文件中访问驱动对象的 getName 方法呢?还是我必须在 CarBean 类中创建一个新方法“getDriverName”?

你能帮助医疗人员吗?BR

4

1 回答 1

1

看这个例子,它很简单:

在 JSF 2.0 中注入托管 bean

于 2010-11-07T20:40:59.110 回答