Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF h:commandLink not work with filter
    text
    copied!<p>I create simple login system for my jsf project. In project I create filter to check user login status.</p> <ul> <li><p>If login, continue to requested page.</p></li> <li><p>If not login or session is destroy, redirect to login page</p></li> </ul> <p>My problem is, if I apply filter then all of h:commandLink not process anything after clicked. But when I remove filter, everything work well. </p> <p>I try to use h:commandButton with fileter, then everthing work correctly.</p> <p>How can I fixed this problem? I research for a long time, but not found any solution. Please help me!</p> <p>Filter code:</p> <pre><code> @WebFilter(filterName = "AuthenticationFilter", urlPatterns = {"*.htm"}, dispatcherTypes = {DispatcherType.FORWARD, DispatcherType.REQUEST}) public class AuthenticationFilter implements Filter { // The filter configuration object we are associated with. If // this value is null, this filter instance is not currently // configured. private FilterConfig filterConfig = null; @Inject private AuthenticationManager authenticationManager; public AuthenticationFilter() { } /** * @param request The servlet request we are processing * @param response The servlet response we are creating * @param chain The filter chain we are processing * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet error occurs */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Throwable problem = null; try { HttpServletRequest req = (HttpServletRequest) request; String requestUrl = req.getRequestURI(); String contextPath = req.getContextPath(); if(contextPath.equals("/")){ contextPath = ""; } String jsfUrl = requestUrl.replaceFirst(contextPath, ""); if (authenticationManager.allowedAccess(jsfUrl) || requestUrl.equalsIgnoreCase(contextPath+"/login.htm")) { chain.doFilter(request, response); } else { String redirectPath = contextPath+"/login.htm"; ((HttpServletResponse) response).sendRedirect(redirectPath); // Not logged in, so redirect to error page. } } catch (Throwable t) { // If an exception is thrown somewhere down the filter chain, // we still want to execute our after processing, and then // rethrow the problem after that. problem = t; } // If there was a problem, we want to rethrow it if it is // a known type, otherwise log it. if (problem != null) { if (problem instanceof ServletException) { throw (ServletException) problem; } if (problem instanceof IOException) { throw (IOException) problem; } sendProcessingError(problem, response); } } /** * Return the filter configuration object for this filter. */ public FilterConfig getFilterConfig() { return (this.filterConfig); } /** * Set the filter configuration object for this filter. * * @param filterConfig The filter configuration object */ public void setFilterConfig(FilterConfig filterConfig) { this.filterConfig = filterConfig; } @Override public void destroy() { } @Override public void init(FilterConfig filterConfig) { this.filterConfig = filterConfig; if (filterConfig != null) { } } } </code></pre> <p>Jsf code:</p> <pre><code>&lt;h:body&gt; &lt;f:view contentType="text/html" locale="#{authenticationManager.languageCode}"&gt; &lt;div class="header"&gt; &lt;h:form id="topForm" prependId="false"&gt; &lt;div class="logo"&gt; &lt;h1&gt;&lt;img src="#{facesContext.externalContext.requestContextPath}/resources/images/login-logo2.png" width="220" height="64"/&gt;&lt;/h1&gt; &lt;/div&gt; &lt;ul class="navTop"&gt; &lt;li&gt; &lt;a href="#"&gt;&lt;span class="pictograms"&gt;f&lt;/span&gt;#{authenticationManager.currentUser.firstName} #{authenticationManager.currentUser.lastName}&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt;&lt;span class="pictograms"&gt;m&lt;/span&gt;Messages&lt;/a&gt; &lt;/li&gt; &lt;li class="logout"&gt; &lt;h:commandButton action="#{authenticationManager.logout()}" value="aaaaaaa" style="color:#fff;" /&gt; &lt;h:commandLink action="#{authenticationManager.logout()}" value="#{label.Logout}"/&gt; &lt;h:commandLink immediate="true" action="#{authenticationManager.logout}" id="logoutLink"&gt; &lt;span class="pictograms"&gt;E&lt;/span&gt;***This link is not work correctly*** &lt;/h:commandLink&gt; &lt;/li&gt; &lt;/ul&gt; &lt;ui:insert name="mainmenu"/&gt; &lt;/h:form&gt; &lt;/div&gt; </code></pre> <p> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload