Problems with if not managedbean

1

I have a login form with the registration and password fields. I'm trying to validate this login where only the registration "92018" can log in the system, but when the logar method is called, it does not pass through if, even if I typed the correct value, I already put a breakpoint to see if the value would be different, but it's not. What could it be?

ManagedBean

public String Logar()
    {
            if(associado.getMatricula()=="92018")
            {
                return "/Teste";    
            }

        return"/sucesso";   
    }

Login form

<h:form id="formLogin">
            <p:fieldset legend="Insira os dados de acesso"
                style="margin-bottom:20px">
                <p:outputLabel for="matricula" value="Matricula: " />
                <br />
                <p:inputText id="matricula" value="#{LoginBean.associado.matricula}"
                    required="true" autocomplete="off" />
                <br />
                <p:outputLabel for="senha" value="Senha: " />
                <br />
                <p:inputText id="senha" value="#{LoginBean.associado.senha}"
                    required="true" />
                <br />
                <br />
                <p:commandButton value="Entrar" id="logar"
                    action="#{LoginBean.Logar}" ajax="false" />
                <br />
            </p:fieldset>
        </h:form>

Class

public class Associado {

    private String matricula,senha;

    public String getMatricula() {
        return matricula;
    }

    public void setMatricula(String matricula) {
        this.matricula = matricula;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }

}
    
asked by anonymous 13.10.2018 / 04:08

1 answer

3

Do not compare strings with == in Java, this will compare the address of the objects containing your words, rather than comparing the words themselves. To compare strings use the equals method, like this:

String palavra = "StackOverflow";

if (palavra.equals("StackOverflow")) {
    //são iguais
}
    
13.10.2018 / 04:19