FileDocCategorySizeDatePackage
ViewForecastAction.javaAPI DocExample1706Sun May 30 01:45:10 BST 2004com.oreilly.strutsckbk.ch04

ViewForecastAction

public class ViewForecastAction extends org.apache.struts.action.Action

Fields Summary
Constructors Summary
Methods Summary
public org.apache.struts.action.ActionForwardexecute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

		// create the weather bean
		WeeklyWeather weather = new WeeklyWeather();		

		// create a list to hold the forecast
		List list = new ArrayList();
    list.addAll( weather.getWeekForecast() );

    // get the sort by request param
    String sortBy = request.getParameter("sortBy");

    // get the reverse request param
    boolean reverse = false;
    String reverseParam = request.getParameter("reverse");
    if (reverseParam != null) 
    	reverse = Boolean.valueOf(reverseParam).booleanValue();

    // sort the list
    if (sortBy != null) {
      Comparator comparator = new BeanComparator(sortBy);
      if(reverse) comparator = new ReverseComparator(comparator);
      Collections.sort( list, comparator );
    }
    
    // add the list as a request attribute and forward to the JSP
    request.setAttribute( "weekForecast", list );
    return mapping.findForward("success");