Re: T5: Ajax response content-tpye

2009-02-26 Thread Zsombor Nemestóthy

Hi,

I've found a solution: overriding the AjaxPartialResponseRenderer service.
In my module class I put this:
public static void bind(ServiceBinder binder) {
   binder.bind(AjaxPartialResponseRenderer.class, 
StbAjaxPartialResponseRenderer.class).withId("StbAjaxPartialResponseRenderer");

}
public static void 
contributeAliasOverrides(Configuration> configuration,
 
@InjectService("StbAjaxPartialResponseRenderer") 
AjaxPartialResponseRenderer aprr) {
   
configuration.add(AliasContribution.create(AjaxPartialResponseRenderer.class, 
aprr));

}
And here is my StbAjaxPartialResponseRenderer class:
public class AminoAjaxPartialResponseRenderer implements 
AjaxPartialResponseRenderer {


 private final MarkupWriterFactory factory;
 private final Request request;
 private final Response response;
 private final PartialMarkupRenderer partialMarkupRenderer;
 private final String outputEncoding;

 public AminoAjaxPartialResponseRenderer(MarkupWriterFactory factory,
Request request,
Response response,
PartialMarkupRenderer 
partialMarkupRenderer,
@Inject 
@Symbol(SymbolConstants.CHARSET)

String outputEncoding) {
 this.factory = factory;
 this.request = request;
 this.response = response;
 this.partialMarkupRenderer = partialMarkupRenderer;
 this.outputEncoding = outputEncoding;
 }

 public void renderPartialPageMarkup() throws IOException {
 // This is a complex area as we are trying to keep public and 
private services properly
 // seperated, and trying to keep stateless and stateful (i.e., 
perthread scope) services
 // seperated. So we inform the stateful queue service what it 
needs to do here ...
 ContentType pageContentType = (ContentType) 
request.getAttribute(InternalConstants.CONTENT_TYPE_ATTRIBUTE_NAME);
 C*ontentType contentType = new ContentType("text/plain", 
outputEncoding);
 // The original was: ContentType contentType = new 
ContentType(InternalConstants.JSON_MIME_TYPE, outputEncoding);*

 MarkupWriter writer = factory.newPartialMarkupWriter(pageContentType);
 JSONObject reply = new JSONObject();
 // ... and here, the pipeline eventually reaches the PRQ to let it 
render the root render command.

 partialMarkupRenderer.renderMarkup(writer, reply);
 PrintWriter pw = response.getPrintWriter(contentType.toString());
 pw.print(reply);
 pw.flush();
 }
}
This is the exact copy of the internal service class 
AjaxPartialResponseRendererImpl except one line.
This solution works but I should not override an internal service, 
because if i upgrade to a new version and this service changes, my code 
won't work.

Any better solution for my problem? I would appreciate any answer.
Thank you, Zsombor

Zsombor Nemestóthy wrote:

Hi All!

I would like to change the content-type of the ajax response, when 
rendering a component from an ajax request.

The content-type is 'application/json' and it need to be 'plain/text'.
We develop an ip-tv middleware and the setTopBox's browser (Opera 
gogi) can not understand the application/json content-type (I think it 
treats the response as binary data). I handle the ajax response with 
my own javascript code, so 'plain/text' would be fine.
I see from the source code that the mime-type's hard coded at the 
InternalConstants.JSON_MIME_TYPE variable, so i don't know how to 
change it.

Anyone has idea how to accomplish this?

Regards, Zsombor


-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org





T5: Ajax response content-tpye

2009-02-25 Thread Zsombor Nemestóthy

Hi All!

I would like to change the content-type of the ajax response, when 
rendering a component from an ajax request.

The content-type is 'application/json' and it need to be 'plain/text'.
We develop an ip-tv middleware and the setTopBox's browser (Opera gogi) 
can not understand the application/json content-type (I think it treats 
the response as binary data). I handle the ajax response with my own 
javascript code, so 'plain/text' would be fine.
I see from the source code that the mime-type's hard coded at the 
InternalConstants.JSON_MIME_TYPE variable, so i don't know how to change it.

Anyone has idea how to accomplish this?

Regards, Zsombor


-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org