You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by jqzone <jq...@gmail.com> on 2012/08/29 07:32:29 UTC

confused using tapestry page to return json data

Example code like this
page class
@ContentType("application/json")
public class SearchUser extends BasePage {

@ActivationRequestParameter(value="filer")
private String filter;


private String staffId;
 protected void onActivate(String staffId){
this.staffId = staffId;
}
 StreamResponse onActivate(){
JSONObject json= new JSONObject();
...
return new TextStreamResponse("application/json", json.toString());
}
}

page tml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:t="
http://tapestry.apache.org/schema/tapestry_5_3.xsd"
xmlns:p="tapestry:parameter">

</html>

sometimes it works fine,it can return json data,but when i restart web
server ,this just return a pure html like below

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html
xmlns="http://www.w3.org/1999/xhtml"><head><link type="text/css"
rel="stylesheet"
href="/assets/2012082913/ctx/default/tapestry/default.css"/><link
type="text/css" rel="stylesheet"
href="/assets/2012082913/ctx/default/jqueryui/redmond/jquery-ui-1.8.21.custom.css"/></head></html>

and when i delete page tml and restart server ,it work fine .but where i
restart server again ,the page throws a exceion  :

Page ***** did not generate any markup when rendered.



So my questions are  :

Does page returning json data need a tml file? If it needs ,how to avoid to
generate html output?

Re: confused using tapestry page to return json data

Posted by Lance Java <la...@googlemail.com>.
After re-reading your code, I see that you have two onActivate() methods with
different parameter counts. Perhaps you are witnessing the behaviour
mentioned here
http://tapestry.1045711.n5.nabble.com/multiple-onActivate-methods-in-page-handler-td2434569.html

Whenever I need to handle a variable number of arguments, I always use a
SINGLE onActivate(EventContext) method. 





--
View this message in context: http://tapestry.1045711.n5.nabble.com/confused-using-tapestry-page-to-return-json-data-tp5715865p5715904.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: confused using tapestry page to return json data

Posted by jqzone <jq...@gmail.com>.
Yes ,I do think  pages / components don't need a template,I'm using
tapestry 5.3.4

On Wed, Aug 29, 2012 at 4:49 PM, Lance Java <la...@googlemail.com>wrote:

> Pages / components don't need a template. If your page always returns a
> StreamResponse from onActivate() then it should not have a template.
>
> I'm  not sure why you're seeing this strange behaviour though? I would have
> assumed that tapestry would ignore the TML.
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/confused-using-tapestry-page-to-return-json-data-tp5715865p5715871.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: confused using tapestry page to return json data

Posted by Lance Java <la...@googlemail.com>.
Pages / components don't need a template. If your page always returns a
StreamResponse from onActivate() then it should not have a template.

I'm  not sure why you're seeing this strange behaviour though? I would have
assumed that tapestry would ignore the TML.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/confused-using-tapestry-page-to-return-json-data-tp5715865p5715871.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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