JSF Facelet应用程序无法在jboss AS 7中运行 [英] JSF facelet app not working in jboss AS 7

查看:99
本文介绍了JSF Facelet应用程序无法在jboss AS 7中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows 7计算机上为Java/JSF应用程序设置环境.我正在将eclipse juno与从eclipse市场下载的Jboss AS 7一起使用.我也在使用JDK 1.7. 我创建了一个非常简单的应用程序,仅包含h:outputLabel标签.在部署和运行之前,一切看起来都不错,但是该标记不会呈现.我的意思是说我得到的是空白页. 我为JSF提供的jars是:jsf-api-2.1,jsf-impl-2.1.0-b03.jar,jsf-facelets-1.1.14.jar. 还有常见的共同点和jstl jars.

I am trying to set up environment for Java/JSF app in my windows 7 machine. I am using eclipse juno with Jboss AS 7 downloaded from the eclipse market. Also I am using JDK 1.7. I created a very simple app containing just a h:outputLabel tag. Everything looks fine until deployed and run, but the tag doesn't render. What I mean to say is that I am getting a blank page. The jars I included for JSF are : jsf-api-2.1, jsf-impl-2.1.0-b03.jar,jsf-facelets-1.1.14.jar. And the usual commons and jstl jars.

没有错误或任何异常.我在这里想念什么吗?如果它太简单了,请原谅我,但这只是花费太多时间.

There are no errors or any exceptions. Am I missing anything here? Please pardon me if its too simple but this is just taking too much time.

我自动创建的faces-config xml:

My auto-created faces-config xml:

<?xml version="1.0" encoding="UTF-8"?>

   <faces-config
    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-facesconfig_2_0.xsd"
version="2.0">

</faces-config>   

我的网络xml:

 <?xml version="1.0"?>
<web-app version="3.0" 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_3_0.xsd">
    <display-name>test</display-name>
   <welcome-file-list>
   <welcome-file>NewFile.xhtml</welcome-file>
   </welcome-file-list>
 <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>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
 <servlet-name>Faces Servlet</servlet-name>
 <url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
 <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
 </web-app>

谢谢.

推荐答案

我为JSF提供的jar是:jsf-api-2.1,jsf-impl-2.1.0-b03.jar,jsf-facelets-1.1.14.jar.还有常见的共同点和jstl jars.

The jars I included for JSF are : jsf-api-2.1, jsf-impl-2.1.0-b03.jar,jsf-facelets-1.1.14.jar. And the usual commons and jstl jars.

这里有很多错误.首先,您不需要甚至不应该包含JSF jar.这些已经是由JBoss AS 7实现的Java EE的一部分.

There are quite a lot of mistakes right here. First of all, you don't need and even should not include the JSF jars. Those are already part of Java EE, which is implemented by JBoss AS 7.

第二,您绝对不需要,也绝对不应将单独的Facelets jar与JSF 2.x结合使用. Facelets已经成为JSF 2.x的一部分.

Secondly, you definitely don't need and absolutely should not use the separate Facelets jar in combination with JSF 2.x. Facelets is already part of JSF 2.x.

您也不应该包含JSTL jar. Java EE/Jboss AS也提供了这一功能.如果使用Commons Jars是指Apache Commons,那么它们很好,但是JSF不需要它们.仅当您想直接在应用程序代码中使用它们时,才包括它们.

You also should not include the JSTL jar. That one too is provided by Java EE/Jboss AS. If with commons jars you mean Apache commons, then those are fine but they are NOT needed for JSF. Include them only if you want to use them directly in your application code.

如果您需要这些罐子中的任何一个(您不需要,但应该假设),如果您刚开始使用最新罐子,则也是最佳做法.从版本号看来,您似乎只是选择了一个随机的旧版本.但是同样,您不需要这些罐子.它们由Java EE/JBoss AS 7提供.

If you would need any of those jars (you don't, but suppose), it's also best practice to take the latest ones if you're just starting. From the version numbers it kinda looks like you just took a random old version. But again, you don't need any of those jars. They are provided by Java EE/JBoss AS 7.

我自动创建的faces-config xml:

My auto-created faces-config xml:

您不需要空的faces-config.xml.如果您只是开始,最好删除不需要的所有内容.如果以后需要配置,可以随时添加.

You don't need an empty faces-config.xml. If you're just starting, it might be better to remove everything you don't need. If there's later something you need to configure, you can always add it.

我的网络xml:

My web xml:

对于JSF,您实际上不需要将FacesServlet映射到您使用的扩展.这些已经是默认值.如果遗漏了整个web.xml,则可以通过将.xhtml扩展名更改为.jsf或.faces来请求Facelets(.xhtml)页面.例如.如果您的页面是'NewFile.xhtml',则可以使用localhost:8080/NewFile.jsf或'localhost:8080/NewFile.faces`或'localhost:8080/faces/NewFile.xhtml'进行请求.

For JSF you don't really need to map the FacesServlet to the extensions you used. Those are already the default. If you leave out the entire web.xml, your Facelets (.xhtml) page can be requested by changing the .xhtml extension to .jsf or .faces. E.g. if your page is 'NewFile.xhtml' you can request it using localhost:8080/NewFile.jsf or 'localhost:8080/NewFile.faces` or 'localhost:8080/faces/NewFile.xhtml'.

不幸的是,JSF 2.1没有默认提供 only (IMHO)有用的映射,为此,您确实需要在web.xml中添加一个映射条目:

Unfortunately, the only (IMHO) useful mapping is NOT provided as a default by JSF 2.1 and for that one you do need to add a mapping entry in web.xml:

<servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>      
</servlet-mapping>

因为您的欢迎页面为NewFile.xhtml,所以您需要此* .xhtml映射,也可以完全删除该映射并将welcome-file内容更改为例如NewFile.jsf.

Because your welcome page is NewFile.xhtml, you need either this *.xhtml mapping, OR you can remove the mapping entirely and change the welcome-file content to e.g. NewFile.jsf.

更新:

如果仍然没有显示欢迎页面,则您的项目中肯定还有其他您不了解自己或没有向我们展示的东西.

If the welcome page still doesn't show, there must be something else in your project that you either don't know about yourself or aren't showing us.

尝试从一个非常简单的项目开始,看看它是否在那里工作

Try to start over with a very simple project and see if it works there:

  1. 在Eclipse中,创建一个新的Dynamic Web Project
  2. 使用项目名称:Welcome和目标运行时:JBoss 7.1 Runtime
  3. 删除WebContent/META-INF和WebContent/WEB-INF/lib
  4. http://arjan-tijms.omnifaces.org/2011/08/minimal-3-tier-java-ee-app-without-any.html 到您的项目.然后,您的工作空间应与图片中的工作空间完全一样.
  5. 添加具有以下内容的WebContent/WEB-INF/web.xml:
  1. In Eclipse, create a new Dynamic Web Project
  2. Use project name: welcome and Target runtime: JBoss 7.1 Runtime
  3. Delete WebContent/META-INF and WebContent/WEB-INF/lib
  4. Copy the 3 files from http://arjan-tijms.omnifaces.org/2011/08/minimal-3-tier-java-ee-app-without-any.html to your project. Afterwards your workspace should look exactly like the one in the picture.
  5. Add a WebContent/WEB-INF/web.xml with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">

    <servlet>
        <servlet-name>facesServlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>facesServlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>page.xhtml</welcome-file>
    </welcome-file-list>

</web-app>

仔细检查您的整个欢迎"项目中有4个文件,不多也不少.

Double check you have exactly 4 files in your entire 'welcome' project, not more and not less.

将项目部署到JBoss AS 7.1.可以肯定的是,在服务器"视图中右键单击运行时服务器,然后单击清理...".启动服务器并请求localhost:8080/welcomelocalhost:8080/welcome/.

Deploy your project to JBoss AS 7.1. To be sure, right click on the runtime server in the Servers view and click on "Clean..." Start your server and request localhost:8080/welcome or localhost:8080/welcome/.

我只是使用与我概述的步骤完全相同的步骤在本地进行了测试,并且可以正常工作.

I just tested this locally using the exact same steps I outlined, and it worked.

这篇关于JSF Facelet应用程序无法在jboss AS 7中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆