RequestContext addCallbackParam params not in response

UI Components for JSF
Post Reply
perraudc
Posts: 1
Joined: 27 Oct 2011, 10:13

27 Oct 2011, 11:07

Hi,
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);

	}
}
and my xhtml page

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>
I'm in primefaces 2.2.1 / jsf 2 / jetty

smallya
Posts: 264
Joined: 19 Mar 2010, 19:22
Contact:

05 Dec 2011, 02:19

Not sure what your managedbean's scope is - I hope it is session.
Netbeans 7.2| GlassFish 3.2 | PostgreSQL 9.1| MongoDB | Primefaces 3.4.2
_______________________________________________________________
Subraya Mallya
http://tinyhabit.com |http://twitter.com/tinyhabit

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 51 guests