我正在试验 JSF 和 Primefaces(JSF 2.0.2,PrimeFaces 3.0.5,Spring 3.0.0)。看来我无法从 xhtml 页面访问托管 bean,例如
<h:inputText id="lastName" value="#{personalBean.personal_Basic.firstName}" label="Last Name" required="true" />
请求从命令链接对 bean 方法、服务的调用开始,并返回页面。我可以在服务器控制台 Bean 中看到,服务方法被执行。当我尝试使用上述 bean 属性时,我什么也没看到。但是,我能够访问用于用户会话管理的会话范围 bean。
对不起,如果这个问题太天真了。非常感谢任何解决问题的意见。
下面是我的代码片段。这就是我所说的bean:
<h:form>
<p:commandLink id="ajax" actionListener="#{personalBean.getPersonalInfo}" style="margin-left:5px;">
<h:outputText value="Personal Info" /> <br/>
</p:commandLink>
</h:form>
下面是请求范围的托管 bean。
package com.test.model;
@ManagedBean
@Scope("request")
public class PersonalBean implements Serializable {
private static final long serialVersionUID = 199L;
private Personal_Basic personal_Basic;
private IPersonalService personalService;
@Inject
public PersonalBean(final IPersonalService personalService) {
this.personalService = personalService;
}
public String getPersonalInfo() {
System.out.println("\n\nPersonalBean#getPersonalInfo called...**");
User user = null;
Personal_Basic personal_Basic = personalService.getPersonalBasic();
this.setPersonal_Basic(personal_Basic);
System.out.println("personal_Basic data:"+personal_Basic);
System.out.println("PersonalBean#getPersonalInfo ended...");
return "/page/personal.html";
}
// Getters/setters for class members followed
}
PersonalService 实现使用@Service 进行注释。
下面是 spring 配置 xml 的摘录。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.test"/>
...................
...................
</beans>
以下是 faces-config.xml 的摘录
<?xml version="1.0"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
<resource-bundle>
<base-name>Messages</base-name>
<var>msg</var>
</resource-bundle>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
</application>
...........................
</faces-config>