struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Don Brown <mr...@twdata.org>
Subject [Proposal] Struts 2 Result Selectors
Date Thu, 26 Oct 2006 18:17:23 GMT
A result selector is a mechanism to select a result with a given result 
code through some external means.  This is a great feature stxx [1] has, 
which I miss in Struts 2.

There are two main problems that this helps to solve:
 1. You want do return different results based on the user's browser 
version.  For example, IE/Firefox users should get an advanced page with 
a lot of Javascript and CSS, while older Netscape 4 browsers will get a 
more simple page.
 2. You want to return different results based on the type of request: 
JSON, XML, or partial HTML.  For example, if the request is for JSON 
data, a result that serializes the data into JSON would be required.  
For a partial HTML page, perhaps a different JSP would be used.

In both cases, you want to separate the selection of the result from the 
Action.  Currently, the action would have to determine, say, if the 
browser is IE and return "success-ie".  A better solution would be to 
let the Action focus on what it does, returning "success", then let a 
Result Selector determine which "success" result to process.  For 
example, the config might look like this:
<action name="ViewFoo" class="mypackage.ViewFooAction">
  <result name="success" when="modern-browser">foo.jsp</result>
  <result name="success" when="netscape4">foo-ns4.jsp</result>
</action>

Or in the second case:
<action name="ViewFoo" class="mypackage.ViewFooAction">
  <result name="success" when="html">foo.jsp</result>
  <result name="success" when="html-partial">foo-partial.jsp</result>
  <result name="success" when="json" type="json" />
  <result name="success" when="xml" type="xml" />
</action>

The value here is, again, your Action stays blissfully unaware of how it 
will be rendered.

I haven't worked out all the details for how this would be implemented, 
only that it would probably need to be put into XWork 2, and should 
allow a chain of result selectors so that the two cases could be combined.

Still, I thought it would be worth getting some feedback.  Does this 
make sense?  Do you think it is worth the new optional "when" 
attribute?  Is there any other cases this would help solve?

Don

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message