1
votes

we are working on a shopping application. we use jsf and primefaces . we have login form on primefaces dialog. The dialog appears on click of add to cart(dlg.show()) if the user is not logged in or else it adds to cart directly. if user login sucessfully then the item is added to cart successfully.

I refered the following example for login dialog.

https://www.primefaces.org/showcase/ui/overlay/dialog/loginDemo.xhtml

I am not sure how do we have callback in primefaces ajax request. based on the response from the login action i want to call add to cart action.

can anyone suggest better approch for this?

1
Where's the "following example"? In any case, have you looked at oncomplete attribute of ajax based components?BalusC
sorry i missed out the linkPadmanabha Vn
so i have add to cart button when clicked will call dlg.show() ..have 2 mbean functions addTOcart and authenticateUser .. I need to call authenicateuser first based on the response i need to invoke addToCartPadmanabha Vn
@BalusC we have oncomplete to call a javascript function oncomplete="handleLoginRequest(xhr, status, args) .. which returns the response of the login .. but how do i invove mben function addTOCart from the javascriptPadmanabha Vn

1 Answers

3
votes

Primefaces provides essentially two options for this:

  1. Primefaces JavaScript API (the hard way), with which you an hook into the Primefacs jsf engine Using the function call Primefaces.ajax.AjaxRequest(cfg). cfg is an array of ajax request parameters that you pass along with the call and can include among other things component ids to ajax process, ids to update,event hooks (oncomplete,onerror etc) and custom request parameters. I'm typing this on a phone so it'll be painful to list an example here but if this is the route you prefer, consult the official Primefaces manual.

  2. <p:remoteCommand/>, the easy way, is implemented as a standard JSF component that gives you all the function and behaviour of a regular JavaScript function and half the typing. With this, you can execute a backing bean function with the behaviour and semantics of a javaScript function