Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loosing reference of the original StringBuilder in the RenderResultPartial #51

Open
BogdanNicolau opened this issue Jul 5, 2012 · 1 comment

Comments

@BogdanNicolau
Copy link

Hi,

Great work on the module. However I have a big problem that's preventing me from upgrading to the latest 0.9.4.3.
Inside my controller, I'm making some final checks on the request parameters trying to see if I need to return a jsonp response. If so, I would've simply done something like:

JapidResult jR = new JapidResult(getRenderResultWith(template(), stuffToRender));
StringBuilder res = jR.getRenderResult().getContent();
res.insert(0, "(").insert(0, callback).append(")");
throw jR;

But now, the RenderResultPartial sends back a new StringBuilder upon every access so my method obviously fails.
It would be optimal to always return the original StringBuilder, and not just enhance a new one every time getContent() is called.

@branaway
Copy link
Owner

branaway commented Jul 6, 2012

Hi,

The reason that a new instance of StringBuilder is returned is due to the
fact the StringBuilder buried inside of the RenderResultPartial is only
part of the text output of the result. It's immutable.

Solutions:

  1. Put the additional checking in the template or in a Java method can be
    in invoked in the template.

Or,
2. Compose a new instance of RenderResult using this constructor:

public RenderResult(Map<String, String> headers , StringBuilder content, *

long* renderTime)

and throw a new instance of JapidResult that wraps the above RenderResult.

Something like this:

RenderResult rr = getRenderResultWith(template(), stuffToRender);
StringBuilder res = rr.getContent();
res.insert(0, "(").insert(0, callback).append(")");
throw new JapidResult(new RenderResult(rr.getHeaders(), res, 0));

Hope this helps.

Bing

2012/7/6 BogdanNicolau <
[email protected]

Hi,

Great work on the module. However I have a big problem that's preventing
me from upgrading to the latest 0.9.4.3.
Inside my controller, I'm making some final checks on the request
parameters trying to see if I need to return a jsonp response. If so, I
would've simply done something like:

JapidResult jR = new JapidResult(getRenderResultWith(template(),
stuffToRender));
StringBuilder res = jR.getRenderResult().getContent();
res.insert(0, "(").insert(0, callback).append(")");
throw jR;

But now, the RenderResultPartial sends back a new StringBuilder upon every
access so my method obviously fails.
It would be optimal to always return the original StringBuilder, and not
just enhance a new one every time getContent() is called.


Reply to this email directly or view it on GitHub:
#51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants