I'm trying to create a sing-in form with an Username(displayed), a Role(hidden) and its Password(hidden) using JSF.
First, the user types his/her Username then clicks on a ''Validate'' button. If the Username exists then the page has to display the Role's<h:SelectOneMenu>
with the Username roles, the Password input and also hide the ''Validate'' button.
The Role and Password inputs are hidden by default via CSS:
<body>
<div class="container">
<h:form styleClass="form-signin">
<h2 class="form-signin-heading">SISE<br><small>Inicio de Sesión</small></h2>
<label for="inputEmail" class="sr-only">Nombre de Usuario</label>
<input type="text" id="inputEmail" class="form-control" placeholder="Nombre de usuario" required autofocus>
<br>
<h:commandButton styleClass="btn btn-lg btn-primary btn-block" value="Validar" action="#{beanInicioSesion.buscarUsuarioDB}" />
<h:selectOneMenu styleClass="form-control hide">
<f:selectItem itemLabel="Something" itemValue="Something"></f:selectItem>
</h:selectOneMenu>
<label for="inputPassword" class="sr-only">Contraseña</label>
<input type="password" id="inputPassword" class="form-control hide" placeholder="Contraseña" required>
<br>
<h:commandButton styleClass="btn btn-lg btn-primary btn-block hide" value="Iniciar sesión" />
</h:form>
</div>
</body>
Here is what I have in my managed user sing-in bean:
public String buscarUsuarioDB() throws SISE_Exceptions, SQLException {
int usuarioValidado = 0; //validatedUser
UsuarioDB usrDB = new UsuarioDB();
try {
usuarioValidado = usrDB.consultarUsuario(this.getNombreUsuario());
if (usuarioValidado == 0) {
setMensaje("Usuario Invalido");
} else {
setMensaje("Usuario Valido");
//Valid user, then show/display the <h:selectOneMenu> and password input.
}
} catch (Exception e) {
// TODO: Add catch code
e.printStackTrace();
}
return "";
}
So the question is, how can I select HTML elements from my buscarUsuarioDB() method in order to set them displayed/hidden within the JSP?