dimanche 1 mars 2015

Different URL-selected views for one controller method in Play framework 2.3



Play, I understand, seperates answers to a request in two layers: The controller method puts all the data together, the view actually creates the output.


I have a function "get customer list". The controller creates, say, a List. Now, what I want is to have two outputs of this controller's result:


1) I want the usual HTML output, so a controller which prints



...<table><tr><th>Name</th>...</tr>
<tr><td>Smith</td>...</tr>
...
</table>...


2) From the same List, I would also create a JSON (or CSV or XML) file containing the customer data as JSON information.


From how I understand Play, it should be possible to obtain this by putting another view renderer at the end of the controller. I would have two URLs, say



/customer/list.html


and



/customer/list.json


which return the two differently formatted results but which use the same controller (which btw. is implemented in Java).


Can this be done? How can this be done? Or is my approach not sensible?


Best regards, Dirk




Aucun commentaire:

Enregistrer un commentaire