You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jacob Hookom <ho...@uwec.edu> on 2002/08/06 20:24:34 UTC

MVC2 Implementation with Tiles [WAP/HTML]

I didn't want to hijack the other MVC thread, but it sparked my interest
in relation to tiles.

Has anyone implemented a framework with the use of Actions and tiles
that would allow the same site to be run for both WAP and HTML?

Where the success or error page itself would look at the request header
and set the content type and then dynamically pick a template to use in
rendering the output from the Action.

// in dispatch action wrapper
public void setUserAgentBean(request,response)
{
String userAgent = req.getHeader("User-Agent");
if {
(userAgent.indexOf("Web") >= 0) response.setAttribute(USER_AGENT,"WEB");
res.setContentType("text/html; charset=ISO-8859-1");
} else if {
(userAgent.indexOf("Wap") >= 0) response.setAttribute(USER_AGENT,"WAP");
response.setContentType("text/vnd.wap.wml; charset=ISO-8859-1");
}
} else if {
(userAgent.indexOf("Palm") >= 0)
response.setAttribute(USER_AGENT,"PALM");
res.setContentType("text/html; charset=ISO-8859-1");
}
}

// in forwarding page
<tiles:insert
definition="examples.<%=response.getAttribute(USER_AGENT)%>.page"
flush="true" />

I know IE has issues with requested resource extensions vs. content
type, do WAP devices have the same problem that you couldn't browse via
Action.do?

Any experience or thoughts would be greatly apprechiated.

Jacob Hookom 
Comprehensive Computer Science 
University of Wisconsin, Eau Claire 



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.380 / Virus Database: 213 - Release Date: 7/24/2002
 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: MVC2 Implementation with Tiles [WAP/HTML]

Posted by Cedric Dumoulin <ce...@apache.org>.
  Hi,

  Actually, the content type is set by the 
RequestProcessor.processContent(...) method. The content type can be 
configured as a parameter of the processor config. This content type is 
overloaded each time you do a forward in the request processing chain, 
because you go through a RequestProcessor again. However, the content 
type can be set only if the response has not been committed (jsp spec), 
so as soon as you will output something in your response, the content 
type is frozen.
  You should also note that when you do a RequestDispatcher.include(...) 
(as Tiles do), your response is flushed, and committed as a side effect.
 
  It is also possible to set the content type in the jsp page itself 
with the directive
<%@ page contentType="wap/text" %>
  This directive is taken into account only if the response is not 
committed.
  When you use Tiles and Struts actions, you can put such directive in 
the first tiles encountered (usually the layout template).
  So you can have something like:
struts-config.xml:
    <action    path="/test/html"
               type="org.apache.struts.tiles.actions.NoOpAction">
            <forward name="success" path="site.mainLayout" />
    </action>

    <action    path="/test/wap"
               type="org.apache.struts.tiles.actions.NoOpAction">
            <forward name="success" path="site.wap.mainLayout" />
    </action>

tiles-def.xml:
  <definition name="site.mainLayout" path="/layouts/classicLayout.jsp">
      <put name="title"  value="Tiles Html Site" />
      <put name="header" value="/tiles/common/header.jsp" />
      <put name="menu"   value="site.menu.bar" />
      <put name="footer" value="/tiles/common/footer.jsp" />
      <put name="body"   value="/tiles/body.jsp" />
  </definition>

  <definition name="site.wap.mainLayout" 
path="/layouts/wapClassicLayout.jsp">
      <put name="title"  value="Tiles Wap Site" />
      ...
  </definition>

And put appropriate contentType directive in each layout.
In this example, you have different URLs for each content type.

  If you want one url serves different content types, you have several 
solutions:

    * Extend TilesRequestProcessor and overload processContent(...) to
      set your own content.
    * Or write your own definition factory serving overloaded
      definitions according to content type (check the tiles channel
      example from the tiles site). In this case you can have one
      definition config file for each content type, and a default config
      file. The factory will serve the definition from the appropriate
      config file if the definition exist, otherwise it serves the
      definition from the default config file. This allows to set all
      definitions in the default config file, and overload only the
      needed ones. For example, you can overload the root definition
      specifying the layout to use.
    * others ??

  Hope this help,

         Cedric


Jacob Hookom wrote:

>I didn't want to hijack the other MVC thread, but it sparked my interest
>in relation to tiles.
>
>Has anyone implemented a framework with the use of Actions and tiles
>that would allow the same site to be run for both WAP and HTML?
>
>Where the success or error page itself would look at the request header
>and set the content type and then dynamically pick a template to use in
>rendering the output from the Action.
>
>// in dispatch action wrapper
>public void setUserAgentBean(request,response)
>{
>String userAgent = req.getHeader("User-Agent");
>if {
>(userAgent.indexOf("Web") >= 0) response.setAttribute(USER_AGENT,"WEB");
>res.setContentType("text/html; charset=ISO-8859-1");
>} else if {
>(userAgent.indexOf("Wap") >= 0) response.setAttribute(USER_AGENT,"WAP");
>response.setContentType("text/vnd.wap.wml; charset=ISO-8859-1");
>}
>} else if {
>(userAgent.indexOf("Palm") >= 0)
>response.setAttribute(USER_AGENT,"PALM");
>res.setContentType("text/html; charset=ISO-8859-1");
>}
>}
>
>// in forwarding page
><tiles:insert
>definition="examples.<%=response.getAttribute(USER_AGENT)%>.page"
>flush="true" />
>
>I know IE has issues with requested resource extensions vs. content
>type, do WAP devices have the same problem that you couldn't browse via
>Action.do?
>
>Any experience or thoughts would be greatly apprechiated.
>
>Jacob Hookom 
>Comprehensive Computer Science 
>University of Wisconsin, Eau Claire 
>
>
>
>---
>Outgoing mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.380 / Virus Database: 213 - Release Date: 7/24/2002
> 
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>  
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>