Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF navigation problem
    text
    copied!<p>Currently i updating a jsf project and a realize a strange thing about project when a jsf page get a request and page returned to client i see page completely in browser after this a new request to same page arrives despite the fact i didnt click any thing i am using navigation handler for navigation.I am using jsf(myfaces),richfaces in my project.</p> <p>i set two break points on these class and i see most of the pages ,not all ,sent request and request goes through menufilter -> myfacesservletwrapper (at that point browser shows page completly)after this menufilter break a nother request for same page .</p> <pre><code>package com.endersys.itap.ui; 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.endersys.itap.ui.module.user.User; import com.endersys.itap.ui.module.user.UserManager; import java.io.FileInputStream; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; public class MenuFilter implements Filter { private String ALLOWED = "login.xhtml"; private String ALLOWED_FOLDER = "a4j"; private static boolean searchEnabled = false; private static boolean syslogServiceEnabled = false; private static String SYSLOG_PAGE= "syslogsettings.xhtml"; private Properties conf; private String SEARCH_PAGE= "search.xhtml"; private static final String BASE_PATH = "/opt/itap/logmonitor/"; private static final String CONF_PATH = BASE_PATH + "etc/logmonitor.properties"; private static Logger logger = Logger.getLogger(MenuFilter.class.getName()); public void destroy() { } public void init(FilterConfig arg0) throws ServletException { if(loadConfiguration()) { if(conf.getProperty("search_enabled").equalsIgnoreCase("true")) { searchEnabled = true; } try { if(conf.getProperty("syslog_enabled").equalsIgnoreCase("true")) { syslogServiceEnabled = true; } }catch(Exception exc) { exc.printStackTrace(); } } } private boolean loadConfiguration() { conf = new Properties(); FileInputStream fis = null; try { fis = new FileInputStream(CONF_PATH); conf.load(fis); } catch (Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); return false; } finally { try { if (fis != null) { fis.close(); } } catch (IOException e) { logger.log(Level.SEVERE, e.getMessage(), e); } } return true; } /** * TODO Unit test this function extensively. */ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { try { UserManager userManager = (UserManager) ((HttpServletRequest) req) .getSession(true).getAttribute("userManager"); // http://localhost:8080/itapgui-v2*/index.xhtml* String relativePath = ((HttpServletRequest) req).getServletPath(); // Servlet path has a leading "/" but our menu items do not. relativePath = relativePath.substring(1); // http://localhost:8080*/itapgui-v2*/index.xhtml String contextPath = ((HttpServletRequest) req).getContextPath(); if(!searchEnabled &amp;&amp; relativePath.endsWith(SEARCH_PAGE)) { ((HttpServletResponse) res).sendRedirect(contextPath + "/index.xhtml"); return; } if(!syslogServiceEnabled &amp;&amp; relativePath.endsWith(SYSLOG_PAGE)) { ((HttpServletResponse) res).sendRedirect(contextPath + "/index.xhtml"); return; } if (!relativePath.endsWith(ALLOWED) &amp;&amp; !relativePath.startsWith(ALLOWED_FOLDER)) { // Permission required. // if (relativePath.endsWith("logout.xhtml")) { // ((HttpServletRequest) req).getSession(true).invalidate(); // ((HttpServletResponse) res).sendRedirect(contextPath // + "/login.xhtml"); // return; // Required. // } if (userManager == null) { // Not authorized. if(relativePath != null &amp;&amp; relativePath.endsWith("index.xhtml")) { ((HttpServletResponse) res).sendRedirect(contextPath + "/login.xhtml"); }else { ((HttpServletResponse) res).sendRedirect(contextPath + "/login.xhtml?session=expired"); } return; // Required. } User user = userManager.getUser(); if (user.getId() == null) { // Not authorized. ((HttpServletResponse) res).sendRedirect(contextPath + "/login.xhtml"); return; // Required. } else if (user.getId() != 1) { Menu menu = (Menu) ((HttpServletRequest) req).getSession(true) .getAttribute("menu"); MenuItem item = menu.getItemByPath(relativePath); if(item != null) { if (!userManager.access(item.getPerms())) { ((HttpServletResponse) res).sendRedirect(contextPath + "/error.xhtml"); return; // Required. } } } } chain.doFilter((HttpServletRequest) req, (HttpServletResponse) res); }catch(Exception exc) { exc.printStackTrace(); if(exc instanceof IOException) { throw (IOException) exc; } else if(exc instanceof ServletException) { throw (ServletException) exc; } } } } public class MyFacesServletWrapper extends MyFacesServlet { private static final String CONN_ERROR_URI = "/dberror.xhtml"; private static final String OTHER_ERROR_URI = "/errors.xhtml"; @Override public void service(ServletRequest request, ServletResponse response) throws IOException, ServletException { try { super.service(request, response); } catch (ServletException e) { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; //if an database exception has occured if (ExceptionUtils.indexOfType(e, javax.persistence.PersistenceException.class) != -1) { res.sendRedirect(req.getContextPath() + CONN_ERROR_URI); } else { // add the exception to the session scope attribute // to show stack trace req.getSession().setAttribute("exception", e); res.sendRedirect(req.getContextPath() + OTHER_ERROR_URI); } } } } </code></pre>
 

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