2014-08-30 2 views
1

struts 2 jquery plugin select 구성 요소를 사용하고 있습니다.Struts 2 jquery sj : select 및 json 결과

동작은 다음과 같습니다

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이 문제는 JSON 플러그인으로, (... anotherList, anString 등) 액션의 모든 속성을 직렬화하는 것입니다

<sj:select list="samples" /> 

입니다 이하

{ 
    "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 pa 램머를 samples으로 설정하면 리턴 된 json에서 samples이라는 목록을 찾을 수 없으므로 js:select이 작동하지 않습니다. 반환 된 json은 다음과 같습니다.

{ 
    "0": {"property":"a"}, 
    "1": {"property":"b"}, 
    "2": {"property":"c"} 
} 

이 문제를 해결할 수 있습니까?

{ 
    "samples": { 
     "0": {"property":"a"}, 
     "1": {"property":"b"}, 
     "2": {"property":"c"} 
     } 
    } 

를 생성하는 내가 스트럿 2 JSON 플러그인을 구성 할 수있는 방법이 있습니까 아니면 어떤 이유 당신은 JSON 결과에 includeProperties 매개 변수를 사용할 수있는 간단한 JSON 배열

답변

1

을 받아 들일에서 플러그인이 JQuery와이 스트럿이다. 예를

@Result(type="json", params = {"includeProperties", "samples.*" }) 

또 하나 개의 샘플

@Result(type="json", params = {"root", "samples", "wrapPrefix", "{\"samples\":", "wrapSuffix", "}"}) 
+0

두 번째는 작동하지만 첫 번째되지하십시오. 첫 번째 것은 비어 있습니다. 그러나 "includeProperties", "samples. *, samples [\\ d +]. *"}'는 작동합니다. 나는 이것을 정확하게 표시 하겠지만, 첫 번째 접근법에 대해서도 제안 할 수 있습니까? –

+0

'samples'로 시작하는 이름과 일치하는 정규식입니다. –

+0

당신이 정확합니다! 그것은 vaid 정규 표현식 인 것 같습니다. 그러나 나는 왜 샘플을 선언해야하는지 모르겠습니다. (아무것도 찾지 못하면 –