Rich Faces 4.0 与 jsf2.0
我正在使用 JSF 2.0 和 Rich Faces 4.0 制作网络应用程序 我想知道 Web.xml 和 config.xml 中的最小条目应该是什么,以便应用程序能够成功运行。 servlet 声明的顺序很重要吗?我是说因为当我使用自定义安全过滤器运行我的应用程序时,丰富的面孔组件有时不会呈现。您能给我示例 Web.xml 文件吗?
编辑:
*谢谢 BalusC *
问题是当我添加安全过滤器时 Rich faces 组件未渲染?我正在感应到我的 web.xml 条目和安全过滤器。你能告诉我我在这里做错了什么吗
</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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在我的项目中遇到了同样的问题,因此我通过在验证中添加加载 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.
Something like this:
对于 JSF 2.0,只需
web.xml
中常见的FacesServlet
映射就足够了。 Faces-config.xml 可以留空。 RichFaces 4.0 不需要在这两个文件中进行额外配置。根据您的更新更新:您需要将安全过滤器映射到不同的 URL 模式。 RichFaces 将在 FacesServlet 的同一映射上动态包含 CSS/JS 文件。但是,您的安全过滤器显然阻止了这些请求(您没有注意日志中的大量系统输出打印吗?)。我建议将受保护的文件放在一个文件夹中,并将过滤器映射到那里,例如
/secured/*
、/private/*
、/app/ *
等。与问题无关,您有很多
FacesServlet
映射。请保持清洁并坚持使用。我个人推荐*.xhtml
。这样,最终用户将无法再通过编辑浏览器地址栏中的 URL 来查看原始 JSF 源代码。Just the usual
FacesServlet
mapping inweb.xml
is enough for JSF 2.0. Thefaces-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.