Struts 2 jquery sj:select and json result(Struts 2 jquery sj:select 和 json 结果)
问题描述
我正在使用 struts 2 jquery 插件选择组件.
I am using struts 2 jquery plugin select component.
动作是:
SampleAction {
       private List<SampleVO> samples; //With setters and getters
       private List<AnotherVO> anotherList; //With setters and getters
       private String anString; //With setters and getters
       @Action(value = "/loadSelect", results = {
       @Result(name = "success", type = "json")})
             public String loadSomeSamples() {
                samples = new ArrayList<SampleVO>();
                //Put some object in samples.
                return SUCCESS;
              }
    }
jsp是
<sj:select list="samples" />
问题在于 json 插件会序列化所有正在运行的属性(anotherList、anString 等...),如下所示
The problem is that the json plugin will serialize all the properties in action ( anotherList, anString etc...), as below
{
  "samples": {
    "0": {"property":"a"},
    "1": {"property":"b"},
    "2": {"property":"c"}
  },
  "anString": "hello",  
  "anotherList": {
    "0": {"prop1":"a","prop2":"b"},
    "1": {"prop1":"c","prop2":"d"}
  }
}
如果我将 json root 参数更改为 samples,那么 js:select 将无法工作,因为它找不到任何名为返回的 json 中的 samples.返回的json是:
If I change the json root parameter to samples, then the js:select will not work as it can not find any list named samples in the returned json. The returned json is:
{
    "0": {"property":"a"},
    "1": {"property":"b"},
    "2": {"property":"c"}
}
这可以解决吗?!有什么办法可以配置struts 2 json插件来生成
Can this be fixed ?! Is there any way I can configure struts 2 json plugin to generate
 {
  "samples": {
        "0": {"property":"a"},
        "1": {"property":"b"},
        "2": {"property":"c"}
      }
  }
或者为什么struts 2 jquery插件接受简单的json数组
Or is there any why struts 2 jquery plugin in accept the simple json array
推荐答案
您可以使用 includeProperties 参数来获取 json 结果.例如
You can use includeProperties parameter to json result. For example
@Result(type="json", params = {"includeProperties", "samples.*" })
再来一个样本
@Result(type="json", params = {"root", "samples", "wrapPrefix", "{"samples":", "wrapSuffix", "}"})
这篇关于Struts 2 jquery sj:select 和 json 结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Struts 2 jquery sj:select 和 json 结果
 
				
         
 
            
        基础教程推荐
- 不推荐使用 Api 注释的描述 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- Java Swing计时器未清除 2022-01-01
 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
						 
						 
						 
						 
						 
				 
				 
				 
				