http://www.developer.com/java/ent/java-tip-spice-up-your-glassfish-authentication-form.html

Back to article

Java Tip: Spice Up Your GlassFish Authentication Form


March 3, 2011

Usually when you develop a GlassFish-based authentication form, you assume that the action should be j_security_check and the fields are j_username and j_password. Knowing that, you can write an HTML form like this:

<form method="POST" action="j_security_check">
    Username: <input type="text" name="j_username" />
    Password: <input type="password" name="j_password" />
    <input type="submit" value="Login" />
</form>

You can spice up this form using JSF code like this:

<form method="POST" action="j_security_check">
    <h:outputLabel for="j_username">Username:</h:outputLabel>
    <h:inputText id="j_username" required="true" />
    <h:message for="j_username" />    
    <h:outputLabel for="j_password">Password:</h:outputLabel>
    <h:inputSecret id="j_password" required="true" />
    <h:message for="j_password" />
    <h:commandButton value="Login" />
</form>

Or, you can take advantage of cool PrimeFaces themes by writing the form like this:

<form method="POST" action="j_security_check">
     <h:outputLabel for="j_username">Username:</h:outputLabel>
     <p:inputText id="j_username" required="true" value="" />
     <h:outputLabel for="j_password">Password:</h:outputLabel>
     <p:password id="j_password" required="true" value="" feedback="false" minLength="0" />
     <h:commandButton value="Login" type="submit" />
</form>

Sitemap | Contact Us