0

I have a Java EE server side REST Service which consumes a POST in JSON format:

@POST
@Consumes(MediaType.APPLICATION_JSON)
public void save(String message) {

    JsonReader reader = Json.createReader(new StringReader(message));
    JsonObject obj = reader.readObject();
    String name = obj.getString("name");
    String surname = obj.getString("surname");
    String address = obj.getString("address");

    Query query=em.createQuery("FROM Person where name = :name and surname = :surname");
    query.setParameter("name", name);
    query.setParameter("surname", surname);
    Person person = (Person) query.getSingleResult();
    person.setAddress(address);
    em.persist(person);
}

This works quite well with an AngularJS front-end. However I'd like to use a solution which can be adapted to work with JSF as well. Unfortunately the only way I can find, with a JSF client is by using another method which uses @FormParam as input.

Is it possible, maybe with some libraries (PrimeFaces) to pass the parameters from an JSF XHTML page as JSON ? Thanks

Tiny
  • 27,221
  • 105
  • 339
  • 599
user2824073
  • 2,407
  • 10
  • 39
  • 73
  • 2
    JSF does the client-server side conversion itself. That's a huge advantage as long as you work with JSF backings at server side, but, for your case, I see it as a huge pitfall. Don't know if you could adapt JSF to manage this case, but I think it wouldn't be trivial. I suggest you going with JSF if you can use its whole view stack. – Aritz Apr 28 '15 at 10:46
  • You could always [POST to a backing bean](http://stackoverflow.com/questions/12750794/jsf-to-receive-post-parameters/12756832#12756832) and perform the conversion there – kolossus May 01 '15 at 13:51

0 Answers0