我有非常简单的 JSF 2.0 应用程序(见下文)。问题是,当ui:repeat
存在时,执行顺序(我在调试器中使用断点检查它)很奇怪。
在我提交表单之后,SecondBean.initSomething()
在之前调用FirstBean.setFirstFormField()
。如果我将类型更改something
为String
并删除并使用,ui:repeat
那么一切都按预期工作,之前调用。index.jsf
h:outputText
FirstBean.setFirstFormField()
SecondBean.initSomething()
我做错了什么?
我正在使用 JDeveloper Studio Edition 11.1.2.2.0 及其堆栈(WebLogic 10.3.5.0、Java 6 和 JSF 2.0)。
这是代码:
index.jsf:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
<html xmlns="http://www.w3.org/1999/xhtml">
<h:head></h:head>
<h:body>
<h:form>
<h:panelGrid columns="1">
<h:inputText value="#{firstBean.firstFormField}" />
<h:commandButton action="#{firstBean.processForm}" value="Submit" />
</h:panelGrid>
</h:form>
<ui:repeat value="#{secondBean.something}" var="variable" >
<h:outputText value="#{variable}" />
</ui:repeat>
</h:body>
</html>
</f:view>
FirstBean.java:
package test.backing;
import javax.faces.bean.*;
import javax.faces.context.FacesContext;
@ManagedBean
@RequestScoped
public class FirstBean {
private String firstFormField;
public FirstBean() {
super();
}
public String processForm() {
FacesContext facesContext;
facesContext = FacesContext.getCurrentInstance();
return facesContext.getViewRoot().getViewId();
}
public void setFirstFormField(String firstFormField) {
this.firstFormField = firstFormField;
}
public String getFirstFormField() {
return this.firstFormField;
}
}
SecondBean.java:
package test.backing;
import java.util.*;
import javax.annotation.PostConstruct;
import javax.faces.bean.*;
@ManagedBean
@RequestScoped
public class SecondBean {
private List<String> something;
public SecondBean() {
}
@PostConstruct
public void initSomething() {
this.something = Arrays.asList("abc", "cde");
}
public void setSomething(List<String> something) {
this.something = something;
}
public List<String> getSomething() {
return this.something;
}
}
面孔-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee">
</faces-config>
网页.xml:
<?xml version = '1.0' encoding = 'UTF-8'?>
<web-app 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-app_2_5.xsd"
version="2.5">
<context-param>
<param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
<param-value>*.jsf;*.xhtml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>