将JQuery与JSF集成 [英] Integrate JQuery with JSF

查看:106
本文介绍了将JQuery与JSF集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主要使用Richfaces的JSF应用程序.我想介绍一个功能更丰富的网格控件,例如基于jQuery的 jqgrid .是否可以从JSF支持bean获得JSON数据?如果没有,是否有替代方法?

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?

推荐答案

这里可能有几个选择.

  1. Bean方法可以返回一个字符串,该字符串只不过是一个JSON字符串

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

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

您可以使用JsonLib将Java对象转换为Json.

You can use JsonLib to convert Java Objects to Json.

使用其他Servlet服务网格请求

Use a different Servlet to service Grid Requests

我将推荐这种方法.原因是您可以拥有一个JSon Request和一个JSON Response,而无需打扰JSF.正如我不认为的那样,当您使用jQuery时,您需要使用JSF.因此,请勿在其中混用JSF,在这种情况下,您可以直接绕过JSF层.由于这里没有意义,这是我使用的方法.我可以与您共享代码以实现此目的.

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.

使用JSF阶段监听器返回Json响应.

Use a JSF Phase Listener to return Json Response.

希望有帮助

这篇关于将JQuery与JSF集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆