Dialog - Login Demo

This example demonstrates how to create a login dialog. Correct combination is (admin-admin)

Login

Source

<h:form id="form">
    <h:outputLink id="loginLink" value="javascript:void(0)" onclick="PF('dlg').show()" title="login">	
        <p:graphicImage value="/images/login.png" />
    </h:outputLink>

    <p:growl id="growl" showDetail="true" life="3000" />

    <p:dialog id="dialog" header="Login" widgetVar="dlg" resizable="false">

		<h:panelGrid columns="2" cellpadding="5">
			<h:outputLabel for="username" value="Username:" />
			<p:inputText value="#{loginBean.username}" 
					id="username" required="true" label="username" />
			
			<h:outputLabel for="password" value="Password:" />
			<h:inputSecret value="#{loginBean.password}" 
					id="password" required="true" label="password" />
			
			<f:facet name="footer">
				<p:commandButton id="loginButton" value="Login" update="growl" 
					actionListener="#{loginBean.login}" 
					oncomplete="handleLoginRequest(xhr, status, args)"/>
			</f:facet>
		</h:panelGrid>
		
    </p:dialog>
</h:form>

<script type="text/javascript">
	function handleLoginRequest(xhr, status, args) {
        if(args.validationFailed || !args.loggedIn) {
            PF('dlg').jq.effect("shake", { times:5 }, 100);
        } 
        else {
            PF('dlg').hide();
            $('#loginLink').fadeOut();
        }
    }
</script>