开发者

Why login dialog don't disappear when user correctly inserts credentials?(JSF 2.0.)

I am implementing an application managed login mechanism using some primefaces components. I successfully save the user state when the credentials are entered correctly and also make the dialog shake when wrong.

The problem is that when the credentials are entered correctly ,the dialog should also disappear. Instead of that. when credentials are correct the dialog shakes and doesn't disappear automatically.How can i fix that?

this is the part of the JSF page that contains the dialog i mentioned:

<p:dialog id="dialog" header="Login" widgetVar="dlg" modal="true"
        width="400" resizable="false" draggable="false" fixedCenter="true">
        <h:form>
            <h:panelGrid columns="2" cellpadding="5">
                <h:outputLabel for="username" value="Em@il: *" />
                <p:inputText value="#{securityController.email}" id="email"
                    required="true" label="email" validator="#{securityController.validateEmail}"/>


                <h:outputLabel for="password" value="Password: * " />
                <h:inputSecret value="#{securityController.password}" id="password"
                    required="true" label="password" validator="#{securityController.validatePassword}"/>

                <f:facet name="footer">
                    <p:commandButton value="Login" update="growl"                       
                         oncomplete="handleLoginRequest(xhr, status, args)"
                             actionListener="#{securityController.logIn()}"/>
                </f:facet>
            </h:panelGrid>
        </h:form>
    </p:dialog>

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

This is the managed bean that does part of the validation:

@ManagedBean
@RequestScoped
public class SecurityController {
@EJB
private IAuthentificationEJB authentificationEJB;
private String email;
private String password;
private String notificationValue;   

public void logIn() {
    if(authentificationEJB.saveUserState(email, password)) {
        notificationValue = "Dobro dosli";
    }   
}

public void validateEmail(FacesContext context, UIComponent validate,
        Object value) {
    String inputFromField = (String) value;
    String simpleTextPatternText = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    Pattern textPattern = null;
    Matcher emailMatcher = null;
    textPattern = Pattern.compile(simpleTextPatternText);
    emailMatcher = textPattern.matcher(inputFromField);
    if (inputFromField.length() >= 30) {
        FacesMessage msg = new FacesMessage(
                "Pre dugacak email(Ne dozvoljeno)");
        throw new ValidatorException(msg);

    }

    if (inputFromField.length() <= 0) {
        FacesMessage msg = new FacesMessage("Zaboraviliste email adresu");
        throw new ValidatorException(msg);

    }

    if (!emailMatcher.match开发者_StackOverflow社区es()) {
        FacesMessage msg = new FacesMessage(
                "Ne ispravan email. Napisiti email u ispravnom obliku. (Np: markomarkovic@mail.com)");
        throw new ValidatorException(msg);
    }       
}

public void validatePassword(FacesContext context, UIComponent validate,
        Object value) {
    String inputFromField = (String) value;
    String simpleTextPatternText = "^[a-zA-Z0-9]+$";
    Pattern textPattern = null;
    Matcher passwordMatcher = null;
    textPattern = Pattern.compile(simpleTextPatternText);
    passwordMatcher = textPattern.matcher(inputFromField);      

    if (inputFromField.length() <= 0) {
        FacesMessage msg = new FacesMessage("Zaboraviliste lozinku");
        throw new ValidatorException(msg);

    }

    if (!passwordMatcher.matches()) {
        FacesMessage msg = new FacesMessage(
                "Lozinka samo moze da zadrzi slova od A do Z i broja od 0 do 9");
        throw new ValidatorException(msg);
    }       
}

public String getEmail() {
    return email;
}

public String getPassword() {
    return password;
}

public void setEmail(String email) {
    this.email = email;
}

public void setPassword(String password) {
    this.password = password;
}

public String getNotificationValue() {
    return notificationValue;
}

public void setNotificationValue(String notificationValue) {
    this.notificationValue = notificationValue;
}   


I fixed the problem, i modified the login() method like this:

public void logIn() {
    RequestContext context = RequestContext.getCurrentInstance();          
    boolean loggedIn = false;
    if(authentificationEJB.saveUserState(email, password)) {
        notificationValue = "Dobro dosli";
         loggedIn = true;             
         context.addCallbackParam("loggedIn", loggedIn);
    }   
}

I dont know much about javascript but i suppose the dialog spected some kind of response message from the backing bean.

Thanks aniway :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜