JavaEnterprise JavaJava Tip: Spice Up Your GlassFish Authentication Form

Java Tip: Spice Up Your GlassFish Authentication Form

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

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>

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories