Skip to main content

JSF Tip #33 - Stateless JSF

Posted by mriem on November 6, 2013 at 12:41 PM PST

Note this blog is obsolete, see https://www.manorrock.com/blog/ for the current blog

In a previous blog entry I blogged about stateless JSF before, this time I will include the entire page so you can see how silly simple it actually is. And you can also go directly to Subversion to get the sample there.

The entirely stateless page

<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <f:view transient="true">
        <h:head>
            <title>Stateless</title>
        </h:head>
        <h:body>
            <h:form>
                <p>
                    This is completely (view-)stateless.
                </p>
                <h:commandButton value="Submit"/>
            </h:form>
        </h:body>
    </f:view>
</html>

As you can see you can use a form and a commandButton. It will still do a post back it just will not cache the Facelets page so it will rebuild it every time.

Note the code for this sample is available as part of the Glassfish samples (see the subversion repository at http://svn.java.net/svn/glassfish-samples~svn/trunk/ws/javaee7)

And that is it.

Enjoy!