Question

I have an action, that ends with these lines:

String pageVisitJson = new Gson().toJson(pageVisitLogList);
is = new ByteArrayInputStream(pageVisitJson.getBytes());
return SUCCESS;

And the result of this action is:

@Results({
    @Result(name=ActionSupport.SUCCESS , type="stream", params={"contentType", "text/html", "inputName", "is"}),
    @Result(name=ActionSupport.SUCCESS, type="tiles", location="/pageVisitReport.tiles")
})

pageVisitReport.tiles is the page where i need to display the table using display tag. Now, how the input stream is can be accessed in display tag. Is my @Result incorrect or is there something else? the display table will further be processed by jQuery.

Whenever my action is called, it just display all the records on a simple page.

Was it helpful?

Solution

The result name attribute should be unique per action configuration, so the action is able to return this result.

Using a stream result type requires to provide a getter for the stream introduced by the inputName parameter.

The content type returned is text/html so you need to parse this text via javascript. You can use JSON.parse(data). The data will be available to you if you make an Ajax request to the server like $.ajax() by providing the URL mapped to the action. On the success function handler you will get the data.

For the difference and explanation how to use a stream result vs json result to return json string to the client javascript see this answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top