<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>+1</div><div><br></div><div>From a user perspective, i think the route sections looks clean with this approach&nbsp;</div><br><div><div>On Dec 21, 2012, at 9:34 AM, Daniel Bevenius &lt;<a href="mailto:daniel.bevenius@gmail.com">daniel.bevenius@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi,&nbsp;<div><br></div><div><p style="margin-right: 0px; margin-bottom: 15px; margin-left: 0px; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; margin-top: 0px !important; ">I'm working on&nbsp;<a href="https://issues.jboss.org/browse/AEROGEAR-693" style="color:rgb(65,131,196);text-decoration:initial">AEROGEAR-693</a>&nbsp;and trying to figure out how to implement this in the best way.</p><p style="margin: 15px 0px; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; ">At the moment, the default type of ViewResponder is the MvcResponder which forwards to a JSP page. By default, this means that if you do not specify a&nbsp;<em>produces()</em>&nbsp;method on a route, this is what you'll get.</p><p style="margin: 15px 0px; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; ">Now, the media types that are passed to the&nbsp;<em>produces()</em>&nbsp;method determine two things: 1. How to match to Route that is the target of a request, matching the HTTP&nbsp;<em>Accept</em>&nbsp;header. 2. Determining the ViewResponder to be used.</p><p style="margin: 15px 0px; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; ">The issue here is that for both a HTMLResponder and a JSPResponder the media type would in both cases be<em>text/html</em>.<br>
How do we determine which one the users actually has created a view for (jsp or html page)?</p><p style="margin: 15px 0px; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; ">
Well, we need some way to differantiate between a route that will respond with a html view, but which uses a ceratain technique to render the html.</p><p style="margin: 15px 0px; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; ">
How about a introduce a type, MediaType that looks something like this:</p><div class="" style="border: none; padding: 0px; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; ">
<pre style="font-size:13px;line-height:19px;font-family:Consolas,'Liberation Mono',Courier,monospace;word-wrap:break-word;margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(204,204,204);overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px"><span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">class</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">MediaType</span> <span class="" style="font-weight:bold">{</span>

    <span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">static</span> <span class="" style="font-weight:bold">final</span> <span class="">String</span> <span class="">HTML</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(221,17,68)">"text/html"</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">static</span> <span class="" style="font-weight:bold">final</span> <span class="">String</span> <span class="">ANY</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(221,17,68)">"*/*"</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">static</span> <span class="" style="font-weight:bold">final</span> <span class="">String</span> <span class="">JSON</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(221,17,68)">"application/json"</span><span class="" style="font-weight:bold">;</span>

    <span class="" style="font-weight:bold">private</span> <span class="" style="font-weight:bold">final</span> <span class="">String</span> <span class="">mediaType</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">private</span> <span class="" style="font-weight:bold">final</span> <span class="">Class</span><span class="" style="font-weight:bold">&lt;?</span> <span class="" style="font-weight:bold">extends</span> <span class="">Responder</span><span class="" style="font-weight:bold">&gt;</span> <span class="">responderClass</span><span class="" style="font-weight:bold">;</span>

    <span class="" style="font-weight:bold">private</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">MediaType</span><span class="" style="font-weight:bold">(</span><span class="" style="font-weight:bold">final</span> <span class="">String</span> <span class="">mediaType</span><span class="" style="font-weight:bold">,</span> <span class="">Class</span><span class="" style="font-weight:bold">&lt;?</span> <span class="" style="font-weight:bold">extends</span> <span class="">Responder</span><span class="" style="font-weight:bold">&gt;</span> <span class="">responderClass</span><span class="" style="font-weight:bold">)</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">this</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">mediaType</span> <span class="" style="font-weight:bold">=</span> <span class="">mediaType</span><span class="" style="font-weight:bold">;</span>
        <span class="" style="font-weight:bold">this</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">responderClass</span> <span class="" style="font-weight:bold">=</span> <span class="">responderClass</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">}</span>

    <span class="" style="font-weight:bold">public</span> <span class="">String</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">getMediaType</span><span class="" style="font-weight:bold">()</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">return</span> <span class="">mediaType</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">}</span>

    <span class="" style="font-weight:bold">public</span> <span class="">Class</span><span class="" style="font-weight:bold">&lt;?</span> <span class="" style="font-weight:bold">extends</span> <span class="">Responder</span><span class="" style="font-weight:bold">&gt;</span> <span class="">getResponderClass</span><span class="" style="font-weight:bold">()</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">return</span> <span class="">responderClass</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">}</span>

    <span class="">@Override</span>
    <span class="" style="font-weight:bold">public</span> <span class="">String</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">toString</span><span class="" style="font-weight:bold">()</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">return</span> <span class="" style="color:rgb(221,17,68)">"MediaType[type="</span> <span class="" style="font-weight:bold">+</span> <span class="">mediaType</span> <span class="" style="font-weight:bold">+</span> <span class="" style="color:rgb(221,17,68)">", responderClass="</span> <span class="" style="font-weight:bold">+</span> <span class="">responderClass</span> <span class="" style="font-weight:bold">+</span> <span class="" style="color:rgb(221,17,68)">"]"</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">}</span>

    <span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">static</span> <span class="">MediaType</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">html</span><span class="" style="font-weight:bold">()</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">return</span> <span class="" style="font-weight:bold">new</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">MediaType</span><span class="" style="font-weight:bold">(</span><span class="">HTML</span><span class="" style="font-weight:bold">,</span> <span class="">HtmlViewResponder</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">class</span><span class="" style="font-weight:bold">);</span>
    <span class="" style="font-weight:bold">}</span>

    <span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">static</span> <span class="">MediaType</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">jsp</span><span class="" style="font-weight:bold">()</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">return</span> <span class="" style="font-weight:bold">new</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">MediaType</span><span class="" style="font-weight:bold">(</span><span class="">HTML</span><span class="" style="font-weight:bold">,</span> <span class="">JspViewResponder</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">class</span><span class="" style="font-weight:bold">);</span>
    <span class="" style="font-weight:bold">}</span>

    <span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">static</span> <span class="">MediaType</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">json</span><span class="" style="font-weight:bold">()</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">return</span> <span class="" style="font-weight:bold">new</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">MediaType</span><span class="" style="font-weight:bold">(</span><span class="">JSON</span><span class="" style="font-weight:bold">,</span> <span class="">JsonResponder</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">class</span><span class="" style="font-weight:bold">);</span>
    <span class="" style="font-weight:bold">}</span>

<span class="" style="font-weight:bold">}</span>
</pre></div><p style="margin: 15px 0px; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; ">And we could add&nbsp;<em>html()</em>,&nbsp;<em>jsp()</em>, and&nbsp;<em>json()</em>&nbsp;methods to AbstractRoutingModule, so a route that should be handled by a HtmlViewResponder would look like this:</p>
<div class="" style="border: none; padding: 0px; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; "><pre style="font-size:13px;line-height:19px;font-family:Consolas,'Liberation Mono',Courier,monospace;word-wrap:break-word;margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(204,204,204);overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px"><span class="">route</span><span class="" style="font-weight:bold">()</span>
      <span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">from</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">"/plain"</span><span class="" style="font-weight:bold">)</span>
      <span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">on</span><span class="" style="font-weight:bold">(</span><span class="">RequestMethod</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">GET</span><span class="" style="font-weight:bold">)</span>
      <span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">produces</span><span class="" style="font-weight:bold">(</span><span class="">html</span><span class="" style="font-weight:bold">())</span>
      <span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">to</span><span class="" style="font-weight:bold">(</span><span class="">Html</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">class</span><span class="" style="font-weight:bold">).</span><span class="" style="color:rgb(0,128,128)">index</span><span class="" style="font-weight:bold">();</span>
</pre></div><p style="margin: 15px 0px; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; ">To be backward compatible, if a&nbsp;<em>produces()</em>&nbsp;method was not specified it would be the same as specifying:</p>
<div class="" style="border: none; padding: 0px; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 0px !important; "><pre style="font-size:13px;line-height:19px;font-family:Consolas,'Liberation Mono',Courier,monospace;word-wrap:break-word;margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(204,204,204);overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">      <span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">produces</span><span class="" style="font-weight:bold">(</span><span class="">json</span><span class="" style="font-weight:bold">())</span></pre>
</div></div>
_______________________________________________<br>aerogear-dev mailing list<br><a href="mailto:aerogear-dev@lists.jboss.org">aerogear-dev@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/aerogear-dev<br></blockquote></div><br></body></html>