Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

json - Integrate JQuery with JSF

I have a JSF application that uses mostly Richfaces. I would like to introduce a more feature-rich grid control, such as the jQuery-based jqgrid. Is it possible to get JSON data from a JSF backing bean? If not, is there an alternative approach?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There could be couple of options here.

  1. Bean method can return a String which is nothing but a JSON String

    public String getSearchResult(){ 
         results = SearchService.getResults();
         return JsonHelper.convertToJson(results);
    }
    

    You can use JsonLib to convert Java Objects to Json.

  2. Use a different Servlet to service Grid Requests

    I will recommend this approach. Reason is you can have a JSon Request and then a JSON Response, without bothering of JSF. As i dont think when you are using jQuery you need to use JSF. So dont mix JSF in it and you can directly bypass JSF layer for this case. As it doesnt make sense here.This is the approach i used. I can share the code with you to achieve this.

  3. Use a JSF Phase Listener to return Json Response.

Hope it helps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...