【发布时间】:2011-03-20 07:21:05
【问题描述】:
这很令人困惑。我正在为一个类开发一个简单的应用程序并按照示例进行操作,但是该死的 Bean 属性不会设置。代码如下:
豆码:
import java.io.Serializable;
import javax.faces.bean.*;
import javax.faces.event.*;
@ManagedBean(name="dist") // or @Named("dist")
@SessionScoped
public class DistanceConvertBean implements Serializable{
private static final double MILESTOKM = 1.609344;
private static final double KMTOMILES = 0.62137;
private double input;
private String convertTo;
private String outputString;
Eclipse generated getters and setters
Index.xhtml 代码:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:body>
<h:panelGrid columns="3">
<h:outputText value="Distance:"/>
<h:inputText id="inDist" value="#{dist.input}" required="true">
<f:convertNumber maxFractionDigits="2"/>
<f:validateDoubleRange maximum="10000"/>
</h:inputText>
<h:message for="inDist"/>
<h:outputText value="Convert To:"/>
<h:form>
<h:selectOneRadio value="#{dist.convertTo}" required="true">
<f:selectItem itemValue="km" itemLabel="Kilometer"/>
<f:selectItem itemValue="miles" itemLabel="Miles"/>
</h:selectOneRadio>
</h:form>
<h:form>
<h:commandButton value="Convert" action="blah"/>
</h:form>
</h:panelGrid>
</h:body>
</html>
Blah.xhtml 代码:
<h:body>
<h:outputText value="#{dist.input}"/>
</h:body>
所以我在 Index.xhtml 的 InputText 字段中输入 10,然后按命令按钮转到 blah.xhtml。 blah 中的值仍然是 0.0。
我正在使用 Tomcat 7 和 Eclipse Heilos 并创建了一个动态 Web 项目。我确实在 WEB-INF/libs 中有所有 JSF jar。我不明白为什么没有设置 bean 属性。这看起来与您在 COREJSF 示例中找到的那些新手代码完全一样。 Web.xml 使用 2.5 的 servlet,所以我不需要 face-config.xml。
【问题讨论】: