在使用 ajax 行为成功登录后,我正在尝试为相同的 primefaces 组件充电,但我不知道该怎么做。充值的组件必须显示用户的全名,该用户名是通过hibernate dao从数据库中恢复的,并且用户和密码的输入框必须消失。
看法 :
<h:head>
<title>header layout</title>
</h:head>
<h:body>
<h:panelGrid id="loginPanelGrid">
<h:form id="loginForm">
<h:outputLabel for="username" value="Username:" />
<p:inputText value="#{loginManagedBean.username}" id="username" required="true" label="username" />
<h:outputLabel for="password" value="Password:" />
<p:password value="#{loginManagedBean.password}" id="password" required="true" label="password" />
</h:form>
<f:facet name="footer">
<p:commandButton id="loginButton" value="Login" update="okLoginPanelGrid" action="#{loginManagedBean.login(actionEvent)}"/>
</f:facet>
</h:panelGrid>
<p:panelGrid id="okLoginPanelGrid">
<h:outputText id="clienteLogado" value="#{loginManagedBean.loggedClient}" />
</p:panelGrid>
</h:body>
豆 :
@ManagedBean
@SessionScoped
public class LoginManagedBean implements Serializable{
private String username;
private String password;
private Cliente loggedClient;
@ManagedProperty(value="#{clienteDAO}")
private ClienteDAO clienteDAO;
public void login(ActionEvent actionEvent){
RequestContext context = RequestContext.getCurrentInstance();
if( (this.getUsername() != null && !this.getUsername().isEmpty()) &&
(this.getPassword() != null && !this.getPassword().isEmpty()) ){
List<Cliente> clienteLogin = clienteDAO.comprobarLogin(username, password);
if(clienteLogin != null && clienteLogin.size() > 0){
loggedClient = new Cliente();
for(Cliente client : clienteLogin){
loggedClient.setCliente_nombre(client.getCliente_nombre());
loggedClient.setCliente_apellido1(client.getCliente_apellido1());
loggedClient.setCliente_apellido2(client.getCliente_apellido2());
}
}else{
System.out.println("**** There are NO CLIENTS for this user and password selected ****");
}
}else{
System.out.println("**** user or password NOT RECOVERED ****");
}
}