0

ajax 動作でログインに成功した後、同じ primefaces コンポーネントを再充電しようとしていますが、これを行う方法がわかりません。再充電されたコンポーネントは、休止状態の dao によって DB から復元されたユーザーの完全な名前を表示する必要があり、ユーザーとパスワードの入力ボックスは非表示にする必要があります。

意見 :

<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 ****");
    }
}
4

1 に答える 1