Hi, I like the below setup. I have always had the problem of modifying my apps to work with different devices. Half the time my apps are working with hand held devices, the other half with desktop browsers.
Alex -----Original Message----- From: David M. Karr [mailto:[EMAIL PROTECTED]] Sent: February 11, 2002 1:50 PM To: [EMAIL PROTECTED] Subject: Re: Screen Flow based on UserAgent in Struts >>>>> "Sam" == Sam Cheung <[EMAIL PROTECTED]> writes: Sam> Hi, Sam> Is there a way to config Struts to forward a different Sam> jsp based on the User Agent of the HTTP Request? I Sam> would like to use the User Agent to identify the Sam> client type (e.g. where desktop or a mobile phone) and Sam> send out either HTML content or WML content. Sam> I come up this idea, I am wondering if there are Sam> better solutions: Sam> Have a different forward name, different path for each Sam> device type: Sam> For example, in struts-config.xml Sam> <action path="/logoff" Sam> type="org.apache.struts.webapp.example.LogoffAction"> Sam> <forward name="successHTML" Sam> path="/indexHTML.jsp"/> Sam> <forward name="successWML" Sam> path="/indexWML.jsp"/> Sam> </action> Sam> And in the perform method of my action code, I have Sam> something like: Sam> if user agent is desktop Sam> return (mapping.findForward("successHTML")); Sam> else Sam> return ((mapping.findForward("successWML")); I wonder whether it would be useful to have something like this (feel free to imagine better naming & API conventions): <action path="..." name="..." type="..." <forward-group name="success" <choice match=".*mozilla.*" path="/thing.html" /> <choice match=".*kbrowser.*" path="/thing.wml" /> </forward-group> </action> Then, the "mapping.findForward()" method would be overloaded with one that takes a "match" string. The "match" attribute in the "choice" element is a regular expression, which matches against the parameter. In this case, the parameter value you would provide would be the "User-Agent" header. This would allow view selection to be abstracted out of the Action class. Any view could be updated to get an alternate rendering, without changing the Action code. The caveat being that you'd have to agree on what always provides the "match" expression in each Action. The "User-Agent" is a good choice, but other applications might use something else. -- =================================================================== David M. Karr ; Java/J2EE/XML/Unix/C++ [EMAIL PROTECTED] -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>