Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling web services from your JSF code

Let's say that you have a presentation tier in JSF, and that your business tier is accessed using web services. How would you call your web services from JSF?

I was considering to have my backing beans to call the web services, but I just though I could use Ajax with JSF in order to connect to the web services. What would you choose and why? Any other choice you could recommend?

EDIT: I'm using Spring in the business tier, maybe that info may help with the suggestions.

Thanks.

like image 907
Abel Morelos Avatar asked May 17 '10 18:05

Abel Morelos


2 Answers

I'd wrap the web service call in a service class, that is accessed via the managed bean. Thus the front-end will not know how exactly the data comes to it - via web services, or via any other means.

like image 157
Bozho Avatar answered Nov 15 '22 05:11

Bozho


Let's say that you have a presentation tier in JSF, and that your business tier is accessed using web services. How would you call your web services from JSF?

The "classic" approach would be to inject a JAX-WS proxy factory class (generated from the WSDL) in a ManagedBean:

public class ItemController {
    @WebServiceRef(wsdlLocation = "http://localhost:8080/CatalogService/Catalog?wsdl")
    private CatalogService service;

    public DataModel getItems() {
        if (model==null  || index != firstItem){
            model=getNextItems();
        }
        return this.model;
    }
    public DataModel getNextItems() {
        Catalog port = service.getCatalogPort();
        model = new ListDataModel(port.getItems( firstItem,batchSize));
        return model;
    }
}

Sample taken from Sample Application using JAX-WS, JSF, EJB 3.0, and Java.

like image 42
Pascal Thivent Avatar answered Nov 15 '22 05:11

Pascal Thivent