我正在使用JSF 1.2编写的一个相当大的应用程序.JSF 1.2现在已经有6年了.我需要升级到JSF 2.0.这会有多痛苦?我注意到自定义标签中的一些属性已被更改等.
我有一些Facelets文件,如下所示.
WebContent |-- index.xhtml |-- register.xhtml |-- templates | |--userForm.xhtml | `--banner.xhtml :
两个页面都使用/templates目录中的模板.我/index.xhtml在浏览器中打开了.我得到生成的HTML输出.我在/index.xhtml文件中有一个链接/register.xhtml文件.但是,我/register.xhtml没有被解析并返回为普通的XHTML/raw XML而不是生成的HTML输出.当我在浏览器中右键单击页面并执行查看页面源代码时,我仍然看到XHTML源代码而不是生成的HTML输出.看起来模板没有得到应用.
但是,当我在浏览器的地址栏中打开#{...}相似内容<h:body>时,它会正确显示.这是怎么造成的,我该如何解决?
我尝试过xmlns:h="jakarta.faces.html"、xmlns:h="http://jakarta.faces.html"、xmlns:h="https://jakarta.faces.html"和其他类似的字符串,但似乎没有任何效果。
我经历了不同的来源,如:
似乎问题已在jsf 2.2.1中得到修复,其中当我尝试使用时,我面临问题,下面是我的配置:
所引用:
<!DOCTYPE html>
<html lang="#{languageBean.language}"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions"
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
<!-- Enables CTRL+SHIFT+D for activating Facelets debug window -->
<ui:debug />
<f:view locale="#{languageBean.language}" encoding="UTF-8" contentType="text/html">
<!-- Client templates can insert f:metadata here, and this will NOT show up in the showcase page source code -->
<ui:insert name="meta" />
<c:set var="contextPath" value="${pageContext.request.contextPath}"
scope="application" />
<f:loadBundle var="messageResource" basename="MessageResource" />
<h:head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible"
content="EmulateIE8,IE=edge,chrome=1" />
<meta http-equiv="pragma" content="no-cache" />
<meta …Run Code Online (Sandbox Code Playgroud) 我正在阅读http://docs.oracle.com/javaee/7/tutorial/doc/jsf-facelets005.htm#GIQZR上的Java EE 7教程
在我的IDE中的8.5复合组件一章中键入示例代码并在GlassFish4.0上运行示例后,我收到错误
java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.putIfAbsent(ConcurrentHashMap.java:1078)
at com.sun.faces.util.Cache.get(Cache.java:116)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.getComponentMetadata(FaceletViewHandlingStrategy.java:237)
at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:951)
at javax.faces.application.ApplicationWrapper.createComponent(ApplicationWrapper.java:648)
Run Code Online (Sandbox Code Playgroud)
然后我查看本教程的旧版本,我发现了一个区别.
在Java EE 7版本中,email.xhtml代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:composite="http://xmlns.jcp.org/jsf/composite"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>This content will not be displayed</title>
</h:head>
<h:body>
<composite:interface>
<composite:attribute name="value" required="false"/>
</composite:interface>
<composite:implementation>
<h:outputLabel value="Email id: "></h:outputLabel>
<h:inputText value="#{cc.attrs.value}"></h:inputText>
</composite:implementation>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是在Java EE 6版本中
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>This content will not be displayed</title>
</h:head> …Run Code Online (Sandbox Code Playgroud) 我有一个名为test.xhtml的文件我试图在Facelets中使用foreach访问哈希映射,但它没有显示键值对,我的代码如下所示.这是怎么造成的,我该如何解决?
<html xmlns:c="http://java.sun.com/jstl/core" xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<title>JSTL Simple Conditional Execution Example</title>
</head>
<h:body>
<f:view>
<c:forEach var="nameMap" items="${specificationAutogege.details}">
<p> ${nameMap.key}</p>
</c:forEach>
</f:view>
</h:body>
Run Code Online (Sandbox Code Playgroud)
是否可以在Facelets中使用JSTL?
HTML输出呈现如下:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core">
<head>
<title>JSTL Simple Conditional Execution Example</title>
</head>
<body>
<c:forEach var="nameMap" items="{Versnellingsk=A very long text come here, Kleur=ZWART Two, Model=3008, Carrosiere=5 deures MPV, A very long text come here=Date Here, BrandShoert=E, Type=3008 Hybrid4 2.0 HDi, Merk=Peugeot, Bowjaar=2011 Shortgate}" varstatus="true">
<p/>
</c:forEach>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 尽管调用了action属性中的方法,但我的智能想法以红色给出“无法解析符号 f:viewAction”警告f:viewAction。
它也没有为它提供自动完成。当我使用f:view或时,自动完成工作f:viewParam。此外,当我转到xmlns:f="http://java.sun.com/jsf/core链接时,我<tag-name>viewAction</tag-name>在该文件中找不到,所以我猜我没有包含正确的版本?
我的 xhtml 页面:
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
template="components/defaultLayout.xhtml">
<f:metadata>
<f:viewAction action="#{indexBean.init}" />
</f:metadata>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
我的依赖:
<!-- Mojarra api of jsf - needed for tomcat -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.10</version>
</dependency>
<!-- Mojarra Implementation of jsf -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.10</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
如何包含正确的库?为什么这个动作从来没有少被调用过?
我正在尝试使用Glassfish 4.0和Java EE 7 XML命名空间来测试下面的示例.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Title</title>
</h:head>
<h:body>
<h:form>
<ul>
<ui:repeat value="#{appLoad.movieList}" var="movie">
<li>
<h:link value="#{movie.title}" outcome="movie" includeViewParams="true">
<f:param name="id" value="#{movie.id}"/>
</h:link>
</li>
</ui:repeat>
</ul>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
它链接到以下页面movie.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<f:metadata>
<f:viewParam name="id" value="#{appLoad.movieId}"/>
<f:event listener="#{appLoad.movieDetail()}" type="preRenderView"/>
</f:metadata>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2">
<h:panelGrid columns="1" width="400">
<h:panelGrid columns="1">
Title : <h:outputLabel value="#{appLoad.movie.title}"/>
</h:panelGrid>
</h:panelGrid>
</h:panelGrid>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
该#{appLoad}支持bean是
@ManagedBean
@RequestScoped
public class AppLoad { …Run Code Online (Sandbox Code Playgroud)