2010-11-22 6 views
0

결과를 다음과 같이 구성했습니다. 내 사용자 정의 결과 유형. struts2의 결과에 매개 변수를 전달하면 작동하지 않습니다.

<result-types> 
    <result-type name="myBytesResult" class="blahblah.MyBytesResult" /> 
</result-types> 


<action name="myAction" class="blahblah.MyAction"> 
    <result name="success" type="myBytesResult"> 
     <param name="pptId">${pptId}</param> 
    </result> 
</action> 

그리고 내 결과는 pptId에 대한 세터/수완을 가지고 시켜라 또한 pptId에 대한 세터/게터 있습니다. 하지만 내 결과를 확인하면 pptId를 설정하지 않습니다 (결과로 $ {pptId}가 문자열로 표시됩니다). 액션에서 게터를 얻지 못하는 것 같습니다.

같은 이유가 무엇일까요?

코드 시켜라

public String doDefault() { 
     System.out.println("Default Called"); 
     setPptId("MyPpt"); 
     return "success"; 
    } 

    public byte[] getMyImageInBytes() throws Exception { 
     try { 
       //..... 
     } catch (Exception e) { 

     } 
     return null; 

    } 


public String getContentType() { 
    return contentType; 
} 

public void setContentType(String contentType) { 
    this.contentType = contentType; 
} 

public String getPptId() { 
    return this.pptId; 
} 

public void setPptId(String pptId) { 
    this.pptId = pptId; 
} 

MyBytesResult

private String contentType; 

private String pptId; 


public void execute(ActionInvocation invocation) throws Exception { 
    HttpServletResponse response = ServletActionContext.getResponse(); 
     //...Some more code for settign response 
    System.out.println("pt Id[" + this.pptId + "]"); 

} 


public String getContentType() { 
    return contentType; 
} 


public void setContentType(String contentType) { 
    this.contentType = contentType; 
} 


public String getPptId() { 
    return pptId; 
} 


public void setPptId(String pptId) { 
    this.pptId = pptId; 
} 
+0

MyBytesResult 및 MyAction에 대한 코드를 제공해주십시오. –

+0

조치 및 결과 코드 –

답변

0

업데이트 대답은

그래서 뒷조사 후,이 실제로 제대로 작동하는지 나타납니다. 들어오는 데이터를 OGNL 표현식으로 평가하는 것은 결과의 책임입니다. 이것이 리디렉션 및 http 헤더 결과가 작동하는 방법입니다. 다음과 같이 사용자 정의 결과에 스택에 대한 값을 구문 분석 할 수 있습니다 : Javadoc의에서

String resolvedPptId = TextParseUtil.translateVariables(pptId, stack) 

translateVariables을 위해 :

모든 $의 인스턴스 {...}, 그리고 %를 {변환 .. .} expression에서 ValueStack # findValue (java.lang.String)} 호출에 의해 리턴 된 값. 항목이 스택에 을 찾을 수 없으면 (null이 반환 됨) 항목이 스택에 있지만 빈 문자열을 반환하는 것처럼 전체 변수 $ {...}는 이 표시되지 않습니다.

+0

$ {# pptId}이 (가) 작동하지 않았습니다. 그리고 getPptId()도 호출되지 않습니다. 거기에 로거를 추가했습니다. –

+0

나는 약간의 시험을했고 내 대답을 수정했다. –

+0

Worked ..! Thnx ... –

관련 문제