1 year ago

#10399

test-img

Matteo Keli

Problems with browser refresh and PrimeFaces 8

I'm quite new at PrimeFaces as I am migrating from IceFaces. My IceFaces application shows with a single url, page content changes and when hitting F5, current view get refreshed, without reloading the page referred by the url. I expect this behaviour in my Primefaces app too, but this doesn't happen, as I go back to the page referred by the url, the login page in my case.

Is this an expected behaviour?

Below the web.xml:

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">
    <display-name>oweb20-mainweb</display-name>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>none</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.validateXml</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.verifyObjects</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.SKIP_COMMENTS</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
        <param-value>/WEB-INF/extras/extras.xml</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>
        <servlet-name>StickyCaptcha</servlet-name>
        <servlet-class>nl.captcha.servlet.StickyCaptchaServlet</servlet-class>
        <init-param>
            <param-name>width</param-name>
            <param-value>250</param-value>
        </init-param>
        <init-param>
            <param-name>height</param-name>
            <param-value>75</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>StickyCaptcha</servlet-name>
        <url-pattern>/stickyImg</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

The faces-config.xml contains beans and navigation cases and rules, here's an example:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
    <managed-bean>
        <managed-bean-name>SessionBean</managed-bean-name>
        <managed-bean-class>com.sia.mainweb.web.SessionBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
        <managed-property>
            <property-name>updateManager</property-name>
            <value>#{UIUpdateManager}</value>
        </managed-property>
    </managed-bean>
    <navigation-rule>
        <from-view-id>/*</from-view-id>
        <navigation-case>
            <from-outcome>caseHome</from-outcome>
            <to-view-id>/Home.xhtml</to-view-id>
        </navigation-case>
    </navigation-rule>
</faces-config>

To navigate between pages, in actions, I use to return the case of the page I want to go, without redirecting to that page:

    public String home_action() {
        logger.info(BaseLogging.methodName() + getTraceEnteringUser());
        String caseName;
        if (userAuthenticated()) {
            boolean canContinue = checkUserFingerprint();
            if (canContinue) {
                caseName = "caseHome";
            }
        } else {
            caseName = "caseNotLoggedOn";
        }
        logger.info(BaseLogging.methodName() + getTraceExitingUser());
        return this.getNavigationManager().navigateTo(caseName);    //returns caseName
    }

java

primefaces

jsf-2

0 Answers

Your Answer

Accepted video resources