Rich Faces 4.0 With jsf2.0

随声附和 提交于 2019-12-11 09:21:57

问题


I am making web app using JSF 2.0 and Rich Faces 4.0 I 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.


EDIT:

*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>

回答1:


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.

Something like this:

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



回答2:


Just the usual FacesServlet mapping in web.xml is enough for JSF 2.0. The faces-config.xml can be left empty. RichFaces 4.0 doesn't require additional configuration in either file.


Update as per your update: you need to map your security filter on a different URL pattern. RichFaces will dynamically include CSS/JS files on the same mapping of the FacesServlet. However, your security filter is apparently blocking those requests (didn't you pay attention to those lot of system out prints in the log?). I'd suggest to put secured files in a folder and map the filter on there instead, e.g. /secured/*, /private/*, /app/*, etc.

Unrelated to the problem, you've got there a lot of FacesServlet mappings. Please keep it clean and stick to one. I'd personally recommend *.xhtml. This way the endusers won't be able to view the raw JSF source anymore by just editing the URL in browser address bar.



来源:https://stackoverflow.com/questions/6010149/rich-faces-4-0-with-jsf2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!