Coverage Report - net.wotonomy.web.WOForm
 
Classes in this File Line Coverage Branch Coverage Complexity
WOForm
0% 
0% 
1.778
 
 1  
 /*
 2  
  Wotonomy: OpenStep design patterns for pure Java applications.
 3  
  Copyright (C) 2000 Blacksmith, Inc.
 4  
 
 5  
  This library is free software; you can redistribute it and/or
 6  
  modify it under the terms of the GNU Lesser General Public
 7  
  License as published by the Free Software Foundation; either
 8  
  version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
  This library is distributed in the hope that it will be useful,
 11  
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
  Lesser General Public License for more details.
 14  
 
 15  
  You should have received a copy of the GNU Lesser General Public
 16  
  License along with this library; if not, see http://www.gnu.org
 17  
  */
 18  
 
 19  
 package net.wotonomy.web;
 20  
 
 21  
 import net.wotonomy.foundation.NSArray;
 22  
 import net.wotonomy.foundation.NSDictionary;
 23  
 
 24  
 /** 
 25  
 * Implements a FORM element with dynamic bindings.
 26  
 * @author michael@mpowers.net
 27  
 * @author $Author: cgruber $
 28  
 * @version $Revision: 905 $
 29  
 */
 30  
 public class WOForm extends WODynamicElement {
 31  
 
 32  
     public WOForm() {
 33  0
         super();
 34  0
     }
 35  
 
 36  
     public WOForm(String n, NSDictionary m, WOElement t) {
 37  0
         super(n, m, t);
 38  0
     }
 39  
 
 40  
     public String href(WOContext c) {
 41  0
         return (String)valueForProperty("href", c.component());
 42  
     }
 43  
 
 44  
     public String directActionName(WOContext c) {
 45  0
         return (String)valueForProperty("directAction", c.component());
 46  
     }
 47  
 
 48  
     public String directActionClass(WOContext c) {
 49  0
         return (String)valueForProperty("actionClass", c.component());
 50  
     }
 51  
 
 52  
     public boolean multipleSubmit(WOContext c) {
 53  0
         return booleanForProperty("multipleSubmit", c.component());
 54  
     }
 55  
 
 56  
     public void takeValuesFromRequest (
 57  
             WORequest aRequest, WOContext aContext)
 58  
     {
 59  0
         if ( rootElement != null )
 60  
         {
 61  0
             rootElement.takeValuesFromRequest( aRequest, aContext );
 62  
         }
 63  0
     }
 64  
         
 65  
     public void appendToResponse(WOResponse r, WOContext c) {
 66  
         //Append the opening tag
 67  0
         r.appendContentString("<FORM");
 68  0
         String link = href(c);
 69  
         //Append the href, if present
 70  0
         if (link != null) {
 71  0
             r.appendContentString(" HREF=\"");
 72  0
             r.appendContentString(link);
 73  0
             r.appendContentString("\"");
 74  0
             link = null;
 75  0
         } else {
 76  0
             link = directActionName(c);
 77  
         }
 78  
 
 79  
         //otherwise, append Direct Action
 80  0
         if (link != null) {
 81  0
             r.appendContentString(" HREF=\"");
 82  0
             if (directActionClass(c) != null)
 83  0
                 link = directActionClass(c) + "/" + link;
 84  0
             r.appendContentString(c.directActionURLForActionNamed(link, urlFields(c.component())));
 85  0
             r.appendContentString("\"");
 86  0
             link = null;
 87  
 //        } else if (associations.objectForKey("action") != null) {
 88  0
         } else {
 89  
             //finally, append action
 90  0
             r.appendContentString(" action=\"");
 91  0
             r.appendContentString(c.componentActionURL());
 92  0
             r.appendContentString("\"");
 93  
         } //else
 94  
 // now defaulting to action if not specified(?): WOBuilder does generate WOForms without any bindings(!)        
 95  
 //            throw new IllegalArgumentException("You must use one of directActionName, action, or href.");
 96  
 
 97  
         //Append any additional properties
 98  0
         link = additionalHTMLProperties(c.component(), new NSArray(new Object[]{
 99  0
             "href", "action", "directActionName", "actionClass", "multipleSubmit" }));
 100  0
         if (link.length() > 0)
 101  0
             r.appendContentString(link);
 102  0
         r.appendContentString(">");
 103  
         //Notify that we're inside a form now
 104  0
         c.setInForm(true);
 105  
         //Append the inner template
 106  0
         rootElement.appendToResponse(r, c);
 107  
         //Close the tag
 108  0
         r.appendContentString("</FORM>");
 109  
 //        c.deleteLastElementIDComponent();
 110  0
         c.setInForm(false);
 111  0
     }
 112  
 
 113  
     public WOActionResults invokeAction(WORequest r, WOContext c) {
 114  
         //We only process the request if it's not a multipleSubmit (otherwise we leave it to the buttons)
 115  0
         if (!multipleSubmit(c) 
 116  0
             && c.elementID().equals(c.senderID()) 
 117  0
             && associations.objectForKey("action") != null ) {
 118  0
             return (WOActionResults)valueForProperty("action", c.component());
 119  
         }
 120  0
         WOActionResults res = rootElement.invokeAction(r, c);
 121  0
         return res;
 122  
     }
 123  
 
 124  
 }