初めて Eclipse で JSF 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
はサブフォルダの templates にあり、次の場所にあります。
<?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>
index.xhtml の「h」タグを含むすべてのコードを削除すると、ファイルは 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}": ターゲットに到達できません。識別子 'login' が null に解決されました
おそらくxmlns:h="http://java.sun.com/jsf/html"
、テンプレート ファイルの行が何かを台無しにしているのでしょうが、テンプレートの全体的な考え方は、テンプレート ファイルにできるだけ多くの共通コードを含めることです。
何が起こっているのか、そしてこれに対する解決策は何ですか?
web.xml
とは標準であり、faces-config.xml
何もする必要はないと思います。