views:

83

answers:

3

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.

+4  A: 

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.

Bozho
elduff
Thanks again Bozho, I'm taking this approach.
Abel Morelos
+2  A: 

I would implement EJBs and expose them as web service (for language independet remote access) within the application I would access the EJBs by lookup and direct call them (for better performance). Unfortunatly you did not tell what platform you're using, so I can't be sure whether my suggestions would be feasible.

stacker
I'm using Spring in the business tier.
Abel Morelos
A: 

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.

Pascal Thivent