Getting tml page output without HTML tags

I am using Tapestry5.3. I have a dynamic web project (prject name: test) with test.tml and test.java.

Test.tml

<!DOCTYPE html>
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
      xmlns:p="tapestry:parameter">

<head>
</head>
<body>
${stringValue}
</body>
</html>

Test.java

public String getGenerateJson() {
return "welcome";
}

I have one more dynamic web project (project name: test2) with test2.tml and test2.java. Both projects are running into my tomcat server.

From test2.java, I make a http connetion to test.java for getting olny test.java return value (welcome) in test2.java.

Test2.java

final GetData data = new HttpGetData();
final String str = data.getContent("http://10.0.1.62:8080/Test/test");
System.out.println("String: " + str); 

Output:

String:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><link type="text/css" rel="stylesheet" href="/test/assets/1b4371c8cdb7af3/core/default.css"/><link type="text/css" rel="stylesheet" href="/test/assets/1b4371c8cdb7af3/jquery/themes/ui-lightness/jquery-ui-1.8.15.custom.css"/><meta content="Apache Tapestry Framework (version 5.3.1)" name="generator"/></head><body>
welcome
</body></html>

But I got output like that.

Is chance to get only welcome from test.java. Please give me your valuable suggestion or idea to achieve like that.

Answers


The simplest solution is to return a StreamResponse from your page's onActivate event. You won't need a template (.tml) to do this.

Object onActivate(EventContext context) {
   return new TextStreamResponse("text/plain", "welcome");
}

Since plain text isn't a great solution, you'll probably want to use JSON instead.

Object onActivate(EventContext context) {
   JSONObject json = new JSONObject("greeting", "welcome");
   return new TextStreamResponse("application/json", json.toCompactString());
}

For a simple way of creating restful webservices in tapestry, you might want to consider tapestry-resteasy


Need Your Help

How can I speed up hybrid property queries in SQLAlchemy?

python sql postgresql sqlalchemy

Is there a good way to speed up querying hybrid properties in SQLALchemy that involve relationships? I have the following two tables:

C++ - Using a copy constructor when returning an object-pointers?

c++ pointers constructor

There are three reasons why you should use a copy constructor when your class has a pointer. One of those is when a function returns a value of the class type. I was wondering what that meant? My g...