本文介绍了带有jsf2.0的Rich Faces 4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSF 2.0和Rich Faces 4.0制作Web应用程序我想知道Web.xml中的最小入口是什么,并且面对config.xml,这样应用程序才能成功运行.声明Servlet的顺序很重要,因为我在运行带有自定义安全过滤器的应用程序时,Rich Faces组件有时无法呈现.能否请给我一个示例Web.xml文件.

I am making web app using JSF 2.0 and Rich Faces 4.0I want to know what should be minimum- entry in Web.xml and faces config.xml so that application will run successfully . Is order of servlet declaration matters , I am saying because when i am running my app with custom security filter, rich faces component is not rendering sometime . Can you please give me example Web.xml file.

* 感谢BalusC *

问题是当我添加安全过滤器时,Rich Faces组件未呈现?我感觉到我的web.xml条目和安全筛选器.你能告诉我我在这里做什么错了吗

*Thanks BalusC *

Problem is when i am adding security filter Rich faces component is not rendered ?? I am sensing you my web.xml entry and security filter. can you please tell me what is wrong i am doing here

</p><p> `<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>MyApp</display-name>

<context-param>
    <param-name>org.richfaces.skin</param-name>
    <param-value>classic</param-value>
</context-param>
<context-param>
    <param-name>org.richfaces.enableControlSkinning</param-name>
    <param-value>true</param-value>
</context-param>
<context-param>
    <param-name>org.richfaces.enableControlSkinningClasses</param-name>
    <param-value>false</param-value>
</context-param>

<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>/faces/*</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>


<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>*.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>*.xhtml</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>SecurityFilter</filter-name>
    <filter-class>com.my.SecurityFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>SecurityFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>

</web-app>`   </p><p> Security Filter </p>  <p>  `import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ils.core.util.IlsUtil;

/**
 * @author --FILTER implementing class; Checks the authentication of every
 *         request
 */
public class SecurityFilter implements Filter {

public void init(FilterConfig config) throws ServletException {
}

public void doFilter(ServletRequest request, ServletResponse resp,
        FilterChain chain) throws IOException, ServletException {
    System.out.println("--------SecurityFilter.doFilter()--------");
    boolean redirToLoginPage = false;
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    InputParamDto parameter = null;
    Object user = null;
    try {
        parameter = (InputParamDto) httpRequest.getSession().getAttribute(
                "inputParameter");
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (parameter == null || IlsUtil.ifEmpty(parameter.getConsumer_id())) {
        redirToLoginPage = true;
    }
    if (httpRequest.getRequestURI().indexOf("login") == -1
            && redirToLoginPage) {
        HttpServletResponse httpResponse = (HttpServletResponse) resp;
        httpResponse.setContentType("text/plain");
        httpResponse.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
        String redirTo = httpRequest.getScheme() + "://"
                + httpRequest.getServerName() + ":"
                + httpRequest.getServerPort()
                + httpRequest.getContextPath() + "/";
        httpResponse.setHeader("Location", redirTo);
    } else {
        chain.doFilter(request, resp);
    }

}

public void destroy() {
}
}`</p>

推荐答案

我在项目中遇到了同样的问题,因此我通过在验证中添加了加载Richfaces资源和jsf的路径来解决了这个问题.

I had the same issue in my project so I solved it by adding the path in the validation where the richfaces resources and jsf are being loaded.

类似这样的东西:

String uri = hr.getRequestURI();            
if (uri.endsWith(".view")
                && !uri.contains(ResourceHandler.RESOURCE_IDENTIFIER)
                && !uri.contains(ResourceHandlerImpl.RICHFACES_RESOURCE_IDENTIFIER)) {
            //You put your code here
}

这篇关于带有jsf2.0的Rich Faces 4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 12:23