[Webwork-user] I18n and more
Brought to you by:
baldree,
rickardoberg
From: Rickard O. <ri...@jb...> - 2000-12-04 21:20:48
|
Hey Following Edwins advice I have begun converting the JavaWorld article on i18n to WebWork. It is pretty straightforward, aside from the fact that the original really is *JSP* with all that comes with that *shiver*. So, a bit of "shaping up" has been done, which made it easier to read, but also a little bigger in terms of number of classes. Nevertheless, it was fairly easy to do so, and I'm very glad I did it because it showed two things that are missing from WebWork. Two tags to be precise. First of all, currently generic components are now done as small jsp:included JSP's which are customized with parameters. They all have a "label" parameter which denotes the label of the component. The problem is that it is not possible to have dynamic content for the label in any easy way. The reason is the way it is supplied, which is as a jsp:param. jsp:param has an attribute "value" which has a runtimeexpression as value. This does indeed allow for extraction of dynamic content for the value, but it would be nicer to be able to use WebWork properties. I.e. instead of: <jsp:param name="label" value="<%=((SomeAction)pageContext.getAttribute("result")).getTexts().getStr ing("somefield.label")%>"/> I would want to do: <jsp:param name="label"><webwork:property name="texts:somefield.label"/></jsp:param> i.e. let the body of the param tag be its value. This is not how jsp:param works, but I have already created a webwork:param which works like the way I want it to for the URL tag. What I will do now is to adapt it to also work with a new webwork:include tag, which will be a replacement for jsp:include. By doing this we can i18n'alize components' labels much easier. I hope you see how by the above. The second thing that is needed is a "quick action" for formatting output. The Actions in WebWork are somewhat coarsegrained and are used for either page or component processing. However, in the i18n example there is a place where a currency is converted to another currency, and the currency name is appended. E.g. $1 is converted into 8.93 SEK. This kind of field-by-field processing is a bit cumbersome to do as Actions. I have actually done that with this particular example, and it looked something like this: <jsp:include page="i18n.ConvertPrice?result=price.jsp" flush="true> <jsp:param name="price" value="1"/> </jsp:param> where price.jsp is: <taglib ...> <webwork:property name="realPrice"/> So, all that happens in ConvertPrice is that a conversion to a given locales currency is done. To use actions and includes for this is somewhat awkward and obscure. Here's is a suggestion for an alternative solution. Introduce a tag "action" which takes an action name as parameter, and which is executed as usual, but its result from execute() is ignored and instead the action is made available (for use by the property tag, for example) during the execution of its body. Like this: <webwork:action name="i18n.ConvertPrice"> <webwork:param name="price"><webwork:property name="cd:price"/> <!-- at this point the ConvertPrice action has been instantiated, its setPrice method has been called, and execute() has also been called --> <webwork:property name="realPrice/> <!-- call getRealPrice on action to print out the converted price including currency type indication --> </webwork:action> This would allow the MVC paradigm to be preserved, but allow for much more lightweight usage than the usual action->jsp model. The above is somewhat flawed still (how to determine when to call execute(), what happens if execute() wants to show some error view, etc.) so if you have any ideas on the above, speak up :-) regards. Rickard |