简体   繁体   中英

JSF 2 doesn't work on WebSphere 7 - Redirecting to JSP

I have a application that runs very well on JBoss using JSF 2. I saw the problems related with the JSF 2, WebSphere and Class Loader. At this time, I see the message "Initializing Mojarra 2.1.7 for the context '/medicao-web'". Then, I think that the class loader is loading the correct JSF classes.

I have a index.jsp that is used to redirect to index.jsf. When I tried to request index.jsf, it makes a infinite loop and a lot of exceptions. In the stacktrace, there's a "at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)", then I think that it's using the FacesServlet at some time. But I also see in the log that the problem related to the JSF is that it's trying to read a JSP.

I also tried to request a different page, that there's no JSP with the same name. After requesting arquivo.jsf, I get:

java.io.FileNotFoundException: JSPG0036E: Failed to find resource /arquivo.jsp
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.findWrapper(AbstractJSPExtensionProcessor.java:360)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.handleRequest(AbstractJSPExtensionProcessor.java:331)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:325)
    at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:415)
    at com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:491)
    at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:159)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1443)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1384)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:852)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:785)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:443)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:175)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3610)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:274)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:926)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1557)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:173)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:272)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:202)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:766)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:896)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)

This is my web.xml:

<?xml version="1.0"?>
<web-app version="2.5" 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_2_5.xsd">
    <display-name>MedicaoCNI</display-name>
    <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>
    <context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>medicao</param-value>
    </context-param>

    <filter>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
</web-app>

And this is my faces-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xi="http://www.w3.org/2001/XInclude" 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">
    <!-- <lifecycle>
        <phase-listener>org.cni.medicao.util.AuthenticationListener</phase-listener>
    </lifecycle> -->
    <navigation-rule>
        <from-view-id>/*</from-view-id>
        <navigation-case>
            <from-outcome>loginSucesso</from-outcome>
            <to-view-id>/usuario.jsf</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>loginFail</from-outcome>
            <to-view-id>/index.jsf</to-view-id>
            <redirect />
        </navigation-case>
        <navigation-case>
            <from-outcome>logoutSucesso</from-outcome>
            <to-view-id>/index.jsf</to-view-id>
            <redirect />
        </navigation-case>
    </navigation-rule>


</faces-config>

All my pages are in XHTML format. I also added a facelets dependency to my project. And I'm using maven.

I made some configurations to try making the class loader to load PARENT_LAST. I don't know if it's correct, but while the log says that it's load the Mojarra 2.1.7, I think it's ok.

I found a post related with mine, but it isn't solved: JSF 2 Mojarra and Primefaces in WebSphere 7+

Thanks in advance.

UPDATE:

I tried to add the javax.faces.DEFAULT_SUFFIX context param to .xhtml. The result is that when I tried to open the arquivo.jsf, I see the source of the XHTML. Although the log is saying it's initializing the Mojarra 2.1.7, I am feeling that there's some conflict here.

This is my ear-plugin configuration of the ear's maven module:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <version>5</version>
        <defaultLibBundleDir>lib</defaultLibBundleDir>
        <earSourceDirectory>${basedir}\src\main\application\META-INF\ibmconfig</earSourceDirectory>
    </configuration>
</plugin>

At \\src\\main\\application\\META-INF\\ibmconfig, there's the deployment.xml:

<appdeployment:Deployment xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:appdeployment="http://www.ibm.com/websphere/appserver/schemas/5.0/appdeployment.xmi" xmi:id="Deployment_1241112964096">
  <deployedObject xmi:type="appdeployment:ApplicationDeployment" xmi:id="ApplicationDeployment_1241112964096" startingWeight="1" warClassLoaderPolicy="SINGLE">
    <classloader xmi:id="Classloader_1241112964096" mode="PARENT_LAST"/>
    <modules xmi:type="appdeployment:WebModuleDeployment" xmi:id="WebModuleDeployment_1241112964096" startingWeight="10000" uri="medicao-web.war">
      <classloader xmi:id="Classloader_1241112964097" mode="PARENT_LAST"/>
    </modules>
  </deployedObject>
</appdeployment:Deployment>

And in my web's maven module, I have this dependencies:

<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.1.7</version>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>2.1.7</version>
</dependency>
<dependency>
    <groupId>com.sun.facelets</groupId>
    <artifactId>jsf-facelets</artifactId>
    <version>1.1.14</version>
</dependency>
<dependency>
    <groupId>jstl</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>3.2</version>
    <scope>compile</scope>
</dependency>

Is there something wrong? I'm new on WebSphere and I need to use it with JSF 2.

UPDATE:

I removed the jsf-facelets dependency, but it's not working yet. I exported an EAR to see if the deployment.xml is there, but it's not being packaged within the EAR. Is there something wrong?

UPDATE:

Now, I'm following this tutorial: http://www.webspheretools.com/sites/webspheretools.nsf/docs/How%20to%20set%20the%20class%20loading%20policy%20to%20parent%20last%20using%20configuration%20files%20shipped%20within%20the%20EAR

My deployment.xml is under \\META-INF\\ibmconfig\\cells\\defaultCell\\applications\\ defaultApp\\deployments\\defaultApp, and my ear plugin's configuration is:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <version>5</version>
        <defaultLibBundleDir>lib</defaultLibBundleDir>
    </configuration>
</plugin>

This way, the deployment.xml is being packaged when I export the EAR. My deployment.xml is the same as shown in the tutorial.

Anyway, when I deploy my application on WebSphere, it generates a new deployment.xml, ignoring mine. Then, it still loading parent first.

Well, all my configuration was ok. I tried installing the EAR using the console of WebSphere, and it read my deployment.xml. I think that there's something wrong with the WebSphere 7 plugin developed by IBM. It's not installing properly the application, then it's ignoring the deployment.xml.

Now my problem is related with IDE, since it's terrible to manually install the application every time I change it, but this question is not about it.

我认为websphere 7没有桥梁就不支持JSF 2。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM