File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes JSF 2.0 and REST(Jeresy) Integratio Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF 2.0 and REST(Jeresy) Integratio" Watch "JSF 2.0 and REST(Jeresy) Integratio" New topic
Author

JSF 2.0 and REST(Jeresy) Integratio

Pawan Komaram
Ranch Hand

Joined: Dec 08, 2009
Posts: 91
Hi,

What are the ways to integrate JSF 2.0 with REST, here I want to use Jersey implimentation of REST. The idea here is to get the response from REST webservice as JSON and use it in the JSF. What are best ways to achieve this? Can any one give simple log in kind of example to achieve this?

Thanks
Brijesh Verma
Greenhorn

Joined: Apr 20, 2009
Posts: 19
there are two steps

just create interface class and map logical url to resource class

@Path(EmployeeResource.EMP_URL)

interface EmployeeClient{

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("all")
public ClientResponse<Employee> getEmployeeDetails();

}


@Path( EmployeeResource.EMP_URL)
class EmployeeResource{
public static final String EMP_URL = "/service/employee";

@Autowired
EmployeeService. employeeService.;


@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("all")
public Employee getEmployeeDetails(){

return employeeService.getEmployee();

}

finally initialize client in resteasy.xml


now you can use client directly in jsf handler class


Pawan Komaram
Ranch Hand

Joined: Dec 08, 2009
Posts: 91
But how to call getEmployeeDetails() method of EmployeeClient interface from my Managed bean class in JSF and what is the fromate of retun value by getEmployeeDetails() method? wil it be a ClientResponse<Employee> object or JSON? if it is java object then what is the use of having MediaType.APPLICATION_JSON property. If JSON is produced from the method call then how to inject that JSON data into my JSF page from my Manged bean (handler class).
Brijesh Verma
Greenhorn

Joined: Apr 20, 2009
Posts: 19
you have to call client object from you jsf handler class and return type is ClientResponse<Users> in your client class

Remember Users class is not your domain class . it is your bean class which you have create because web service does not understand List<User>

So follow these steps
UserHandler class


@Controller("userHandler")
@Scope("session")
public class UserHandler implements Serializable {

@Resource
private UserClient userClient;

private List<User> users;

public Collection<User> getUsers() {
if (users == null) {

users = userClient.getUsers().getEntity().getUsers();

}
return users;
}

And use this bean class in your client class for return type

@XmlRootElement
public class Users {


private List<User> users = new ArrayList<User>();


public Users() {
}

public Users(List<User> users) {
this.users = users;
}


@XmlElement(name = "user")
public List<User> getUsers() {
return users;
}


public void setUsers(List<User> users) {
this.users = users;
}
}


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF 2.0 and REST(Jeresy) Integratio