Hi,


I am new to the webworks framework but think I am starting to get a handle on it. The documentation is very helpful.

In my initial trials, I came across a problem with using the <ui:radio> tag. As per the tag.jsp doc, ui:radio
behaves as expected when the Collection provided for the list attribute is a Map. (This version is not shown below.) However, when I tested to see how it handled a List, things did not go as well as I had hoped. I added the listKey and listValue attributes, but noticed that when I submitted the form and returned an error message along with the view, the list of radio labels would not display and the values were blank. I got around the problem by using an iterator and catch the loop after the first pass, but this is pretty ugly and somewhat confusing. What I would like to know if this is the best/only way to do this. Why does the radio tag lose the labels upon resubmit? I have looked at the source, but the answer is not, as yet, jumping out at me. Below are the files to show what I am talking about.


TIA,

George

>>>>action.xml
<action name="TownsList" alias="TownsList">
      <view name="success">process.jsp</view>
      <view name="input">correct.jsp</view>
   </action>

>>>>process.jsp which works but is ugly as described above

<%@ taglib uri="webwork" prefix="webwork" %>
<%@ taglib uri="webwork" prefix="ui" %>
<form action="TownsList.action" method="post">
<webwork:action name="'TownsList'" id="towns">
<webwork:param name="'first'" value="0"/>
<webwork:iterator value="towns" status="'col'">
<webwork:if test="@col/first==true">
<ui:radio label="'Town'" name="'town'" list="towns" listKey="'.'" listValue="'.'"/>
</webwork:if>
</webwork:iterator>
</webwork:action>
<hr>
<webwork:if test="hasErrorMessages == true">
Sorry, but <webwork:property value="town" /> isn't correct.
<hr>
<br>
</webwork:if>
<input type="submit" value="Select a Town" >
</form>



>>>>process.jsp which gave me the trouble


<%@ taglib uri="webwork" prefix="webwork" %>
<%@ taglib uri="webwork" prefix="ui" %>
<form action="TownsList.action" method="get">
<webwork:action name="'TownsList'" id="towns">
<ui:radio label="'Town'" name="'town'" list="@towns/towns" listKey="town" listValue="town"/>
</webwork:action>
<hr>
<webwork:if test="hasErrorMessages == true">
Sorry, but <webwork:property value="town" /> isn't correct.
<hr>
<br>
</webwork:if>
<input type="submit" value="Select a Town" >
</form>


>>>>correct.jsp


Congratulations you selected today's secret Town of <ww:property value="town"/> !
<br>
<form action="process.jsp">
<input type="submit" value="Try again"/>
</form>



>>>>TownsList.java


public class TownsList extends ActionSupport
{
  static List towns;
  String town = "";
  static
  {

        towns = new ArrayList();
        towns.add("town1");
        towns.add("town2");
        towns.add("town3");
        towns.add("town4");
        towns.add("town5");
        towns.add("town6");
        towns.add("town7");
    }
    public List getTowns()
    {
        return towns;
    }
    public void setTown(String townname)
    {
        this.town = townname;
    }
    public String getTown()
    {
        return town;
    }
    public String doExecute() throws Exception
    {
        String view = SUCCESS;

        if (getTown().equals("town1"))
        {
            view = INPUT;
        }
        else
        {
            addErrorMessage("Nope that wasn't it");
        }
        return view;
    }
}




------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 _______________________________________________ Opensymphony-webwork mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork

Reply via email to