{% render "AcmeArticleBundle:Article:recentArticles" with {'max': 3} %}
On Thu, Apr 5, 2012 at 10:17 AM, Julien Richard-Foy <j...@zenexity.com> wrote:
> I think you don’t want to call an action. Maybe just a method.
>
> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
--
Guillaume Bort
You can call any controller method from a view. But calling an action
is probably not useful, as Guillaume said.
You’re free to write a method which renders a HTML fragment and call
this method from your ajax action and from your view.
For Scala Action it will, since there is no magic and all filters are
applied by clean function composition. For Java Action it won't since
composition is expressed via Annotations and is applied at runtime by
the framework.
I still don't see how we could embed a Result in an HTML page. What
about the response headers? What if the result is asynchronous
(meaning a promise of Result, only available in 10 seconds)? What if
it a stream? And non 2xx response?
To summarize what if the result is something else than a 200 OK,
Content-Type: text/html without any cookie header?
You talk about simplicity, but allowing that would just add huge
complexity: no one could predict the result of calling an Action from
another Action.
--
Guillaume Bort
// This is an action
public static Result index() {
return ok(
views.html.index(
anHtmlPartialFragment()
)
);
}
// This is an action
public static Result ajaxCall() {
return ok(anHtmlPartialFragment());
}
public static Html anHtmlPartialFragment() {
Items items = // retrieve some values from the database
return views.html.partial(items);
}
Here you get the index action rendering the whole page with the HTML
fragment pre-rendered, and still you can write a ajax action rendering
only the HTML fragment without any code duplication.
The current design we have, with a clear separation between the
template rendering and the HTTP response representation, allow to do
that without any magic or hack. We don't need to introduce something
new.