• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

JSF 2.0 and REST(Jeresy) Integratio

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}
}


 
Police line, do not cross. Well, this tiny ad can go through:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic