I am in the process of trying to integrate our B2B application to Curbstone’s credit card processing service.
The way this process works is that we need to redirect the user to an external URL which will display a page for the user to enter their credit card information.
We send a call back url as part of this redirect for the user to be returned to when they are done processing their credit card.
I created a servlet to handle the call back but I am unable to get back to the FacesContext in the JSF application from this servlet.
I was hoping someone could give me some suggestions on how to handle this process.
No servlet can access FacesContext. FacesContext is created by the FacesServlet when a JSF request comes in, serves as the anchor point for processing that request and building its response, and is destroyed as soon as the response has been sent back to the client.
You can, however, pass a JSF URL to the credit card processing service as its return point. I've done this with PayPal.
An IDE is no substitute for an Intelligent Developer.
Joined: Sep 28, 2012
Thank you for the response.
I am new to JSF.
I will need the call back URL to execute a method that will either redisplay the creditcard info page if there was an error or process the order and display a confirmation page.
Can you point me in the right direction as to how I would accomplish this?
PayPal allowed specifying 2 separate URLs, I think. One got invoked on success, the other got invoked on failure (and included failure codes and messages).
You might want these URLs to be handled by servlets, which could then forward to JSF. Or you could simple make these URLs be JSF URLs. However, if you do that, you'll need to handle the View request processing in your backing bean as a GET request, since the credit card processor isn't going to be returning data in JSF postback form.
Details on how JSF handles HTTP GET have changed since I did it last (JSF2 makes it a lot easier), so I'm not up to date on best practices. In JSF1, I used PrettyFaces, which automatically parsed the returning URL request and injected the response-returned parameters into backing bean properties.
Joined: Sep 28, 2012
I have a servlet which is used for the call back from the Credit card processor. I am still unclear as to how I am suppose to forward from the servlet to JSF.
After my servlet recieves the response form the credit card processor I need to forward to JSF. Do I need to forward to an .xhtml or can I call a method in a managed bean directly?
I tried to call a method in a managed bean directly but I get a nullpointer error from FacesContext.getCurrentInstance().
I think probably reverse order is the best way to answer these questions.
Thirdly, as I said earlier, the FacesContext does not exist when a servlet is executing (unless it's the FacesServlet!). So your NullPointerException is exactly what should happen. However, JSF Manages Beans in Session scope and Application Scope are directly accessible as J2EE Session Objects and Application Objects, respectively. Once a managed bean has been created by the JSF bean manager, it's no different than any other J2EE session or application bean.
Secondly, "xhtml" is a resource. In J2EE, you forward to a URL. So if your target view is "cart/CreditApproved.xhtml", the corresponding URL is (usually) "cart/CreditApproved.jsf". As for calling methods in managed beans, I hope I just answered that in the previous paragraph. The only caveat is that any code in the managed bean - or code called by that code for that matter - must be POJO code, not accessing the FacesContext or other JSF internals. Because they won't exist when invoked outside of the FacesServlet.
And Firstly, forwarding to a JSF URL is done exactly the same way that a servlet (or JSP) would forward to any other URL.