Im' trying to add param to the callback with :
RequestContext context = RequestContext.getCurrentInstance();
context.addCallbackParam("username", username);
but the param is not in the response and of course undefined in the js function
Anyboby can help ?
Here my code :
java : LoginBean.java
Code: Select all
package com.chronopost.maps.controller;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.primefaces.context.RequestContext;
@ManagedBean
public class LoginBean {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public void login(ActionEvent actionEvent) {
RequestContext context = RequestContext.getCurrentInstance();
FacesMessage msg = null;
if(username != null && username.equals("admin")) {
loggedIn = true;
msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", username);
} else {
loggedIn = false;
msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "Invalid credentials");
}
FacesContext.getCurrentInstance().addMessage(null, msg);
context.addCallbackParam("username", username);
}
}
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
<script type="text/javascript">
function handleLoginRequest(xhr, status, args) {
if(args.validationFailed || !args.username) {
jQuery('#dialog').effect("shake", { times:5 }, 100);
} else {
dlg.hide();
jQuery('#loginLink').fadeOut();
}
}
</script>
</h:head>
<h:body>
<h1 class="title ui-widget-header ui-corner-all">Dialog - Login Demo</h1>
<div class="entry">
<h:form>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="username" value="username * " />
<p:password id="username" value="#{loginBeanusername}" label="username" />
<p:commandButton value="Login" update="growl"
actionListener="#{loginBean.login}" oncomplete="handleLoginRequest(xhr, status, args)"/>
</h:panelGrid>
</h:form>
</div>
</h:body>
</html>