我想第一次在Eclipse中使用带有JSF 2.0的模板,但是我遇到了问题。JavaServer Faces 2.0中的模板
原始index.xhtml
页面正常工作,当我点击一个按钮时,一切正常。但是,如果我更改索引页以便它使用模板文件,它将不再正常工作。修改后的index.xhtml
页面是在这里:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/templates/main-template.xhtml">
<ui:define name="title">
Simulator using JSF 2.0 - Test Version 2
</ui:define>
<ui:define name="header">
Home Page of the Simulator using JSF 2.0 - Test Version 2
</ui:define>
<ui:define name="body">
Click on the button to select the required option
<h:outputText value="and login" rendered="#{!login.loggedIn}"/>
<h:form prependId="false">
<h:commandButton value="Option 1" action="#{login.option1}"/>
<h:commandButton value="Option 2" action="#{login.option2}"/>
<h:commandButton value="Option 3" action="#{login.option3}"/>
<h:commandButton value="Logout" disabled="#{!login.loggedIn}" action="#{login.logout}"/>
</h:form>
</ui:define>
</ui:composition>
和模板文件,main.template.xhtml
,是在子文件夹中的模板,是在这里:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>
<ui:insert name="title">Title</ui:insert>
</title>
</h:head>
<h:body>
<ui:insert name="header">Header</ui:insert>
<br/>
We are in template.xhtml
<br/>
<ui:insert name="body">Body</ui:insert>
</h:body>
</html>
如果我删除所有代码与“H”标记在index.xhtml中,文件正确地选取了templates/main-template.xhtml中的代码,因此路径是正确的。不过,如果我在这里包含带有“h”标签的代码,Eclipse会抱怨标签无法识别并且页面失败。
如果我包括在顶部行xmlns:h="http://java.sun.com/jsf/html"
,然后Eclipse中公认的“H”标签和页面正确呈现,但是当我点击一个按钮的应用程序失败,并返回错误:
javax.servlet.ServletException: javax.el.PropertyNotFoundException: /index.xhtml @15,68 action="#{login.option1}": Target Unreachable, identifier 'login' resolved to null
模板文件中的xmlns:h="http://java.sun.com/jsf/html"
行也许会让事情变得糟糕起来,但模板的整体思想是在模板文件中包含尽可能多的常见代码。
有没有人知道发生了什么,以及解决方案是什么?
web.xml
和faces-config.xml
是标准的,并不认为有任何事情要做。
StackOverflow不只是一个论坛,它也是一个wiki和一个博客。请参阅http://www.codinghorror.com/blog/2008/09/stack-overflow-none-of-us-is-as-dumb-as-all-of-us.html – nalply