[Webwork-user] WebWork 0.3 released
Brought to you by:
baldree,
rickardoberg
From: Rickard <ri...@te...> - 2000-11-28 15:57:24
|
All, I just uploaded WebWork 0.3 to CVS and the WebWork homepage (.zip). This is partly a rewrite and partly more functionality. The name parsing functionality is now in one place so that all tags behave the same (i.e. the code that figures out that the name "foo:bar:xyzzy" could translate into the calls "getFoo().get("bar").getXyzzy()". On the functionality side I have added a tag "equals" which can be used to compare values and conditionally do stuff. There are two examples that uses this tag. But I think the most interesting additions are the new examples. They show some nifty patterns on how to use WebWork. For example, there is now a select.jsp that one can include in ones JSP's and which will render a <SELECT> box in a form. It takes a couple of parameters so that one can control what should be in the listing, and how it should determine what option is selected. Here's the example. select.jsp looks like this: <SELECT NAME="<%=request.getParameter("name")%>"> <webwork:iterator name="$list"> <OPTION NAME="<webwork:property/>" <webwork:equals value="$value">SELECTED</webwork:equals>><webwork:property/></OPTION> </webwork:iterator> </SELECT> --- So, it has three parameters: name, list, and value. "name" holds the name of the select box. "list" holds the name of the property which should be used to fill the list box. I.e. if you have a method "Collection getOptions()" then "list" should be set to "options". "value" holds the property that holds the currently selected option. The "list" and "value" properties does not have to be in the same action. This is cool because you can have one action that does a listing of, for example, people, and use it with a bunch of actions that render forms where one can select a person. To complete the example here is the form JSP that includes it: <FORM ACTION="FormTest.action"> <jsp:include page="AgeList.action?result=select.jsp" flush="true"> <jsp:param name="name" value="age"/> <jsp:param name="list" value="ages"/> <jsp:param name="value" value="age"/> </jsp:include> <INPUT TYPE=submit VALUE="Update"> </FORM> This is invoked by calling "FormTest.action". FormTest has methods getAge/setAge, and AgeList has a method "getAges" that returns a list of strings with valid options. So, by the above reasoning, you could in this case reuse the AgeList action in several JSP forms. You can easily make more generic components such as this which take input parameters to render themselves. With regard to iterators, they now work without having to specify a property name. This is useful to traverse, for example, String[][] objects. Let's say your action has a getArray() that returns a String[][] object. Then you can iterate over it by doing: <TABLE> <webwork:iterator name="array"> <TR> <webwork:iterator> <TD><webwork:property/> </webwork:iterator> </TR> </webwork:iterator> </TABLE> This will print a table with the 2D arrays strings as cells. Another very important upgrade was to allow forms to have values that goes to several beans. The way it works is that your action must call Dispatcher.setParameters() with your custom object, which will perform the same thing it does on the action before calling execute(). There is an example available that shows how to use this (MultiForm.java). I have not yet updated EBS to use these new features, but will do so shortly. The easiest way to see this in action is to deploy webwork.war, and surf to "/webwork". There are now links to all the examples so that you can easily try them all out. Have fun! And let me know what you think about this release, and if you think it is heading in the right direction. regards, Rickard -- Rickard Öberg Email: ri...@te... http://www.telkel.com http://www.jboss.org http://www.dreambean.com |