struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lukasz Lenart <lukaszlen...@apache.org>
Subject Re: json result type not parse OGNL expressions in params
Date Mon, 22 Oct 2012 09:41:10 GMT
2012/10/21 JOSE L MARTINEZ-AVIAL <jlmagc@gmail.com>:
> I just reviewed the code, and it seems that the HttpHeaderResult only
> parses the parameters headers and errorMessage, but not the parameters
> status or error. I think it could be a nice thing to have. my workaround is
> to extend JSONResult incorporating the following:
>
> public void setStatusCode(String statusCode) {
>         ValueStack stack = ActionContext.getContext().getValueStack();
>
> setStatusCode(Integer.parseInt(TextParseUtil.translateVariables(statusCode,
> stack)));
> }
>
> public void setErrorCode(String errorCode) {
>         ValueStack stack = ActionContext.getContext().getValueStack();
> setErrorCode(Integer.parseInt(TextParseUtil.translateVariables(errorCode,
> stack)));
> }
>
> It works fine  but I think that this feature should be incorporated to all
> parameters. I would like to know opinions from other people before opening
> a jira issue for this.

It makes sense, please register an issue.

But jus one thing, you should delay expression evaluation to very end
and not to evaluate params when you setting them up, rather when you
using them in a code, like:

public void setErrorCode(String errorCode) {
     this.errorCode = errorCode;
}

and in

protected void writeToResponse(HttpServletResponse response, String
json, boolean gzip) throws IOException {
    int errorCode = evaluate(errorCode);
    JSONUtil.writeJSONToResponse(new SerializationParams(response,
getEncoding(), isWrapWithComments(),
            json, false, gzip, noCache, statusCode, errorCode, prefix,
contentType, wrapPrefix,
            wrapSuffix));
}


Regards
-- 
Ɓukasz
mobile +48 606 323 122 http://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message