View Javadoc
1   /*
2    * Copyright (C) 2003-2009 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.wcm.webui.container;
18  
19  import java.io.Writer;
20  
21  import org.exoplatform.webui.application.WebuiRequestContext;
22  import org.exoplatform.webui.core.UIComponent;
23  import org.exoplatform.webui.core.UIContainer;
24  import org.exoplatform.webui.form.UIForm;
25  
26  /**
27   * Created by The eXo Platform SAS
28   * Author : eXoPlatform
29   * chuong.phan@exoplatform.com, phan.le.thanh.chuong@gmail.com
30   * Jun 26, 2009
31   */
32  public class UIFormFieldSet extends UIContainer {
33  
34    /**
35     * Instantiates a new uI form field set.
36     *
37     * @param name the name
38     */
39    public UIFormFieldSet(String name) {
40      setId(name) ;
41    }
42  
43    /* (non-Javadoc)
44     * @see org.exoplatform.webui.core.UIComponent#processDecode(org.exoplatform.webui.application.WebuiRequestContext)
45     */
46    public void processDecode(WebuiRequestContext context) throws Exception {
47      for(UIComponent child : getChildren())  {
48        child.processDecode(context) ;
49      }
50    }
51  
52    /* (non-Javadoc)
53     * @see org.exoplatform.webui.core.UIComponent#processRender(org.exoplatform.webui.application.WebuiRequestContext)
54     */
55    public void processRender(WebuiRequestContext context) throws Exception {
56      if (getComponentConfig() != null) {
57        super.processRender(context);
58        return;
59      }
60      UIForm uiForm = getAncestorOfType(UIForm.class);
61      Writer writer = context.getWriter() ;
62      writer.write("<div class=\"" + getId() + "\">") ;
63      writer.write("<fieldset>") ;
64      writer.write("<legend>" + uiForm.getLabel(getId()) + "</legend>") ;
65      writer.write("<table class=\"UIFormGrid\">") ;
66      for(UIComponent component : getChildren()) {
67        if(component.isRendered()) {
68          writer.write("<tr>") ;
69          String componentName = uiForm.getLabel(component.getId());
70          if(componentName != null && componentName.length() > 0 && !componentName.equals(getId())) {
71            writer.write("<td class=\"FieldLabel\"><label for=\"" + component.getId() + "\">" + componentName + "</td>");
72            writer.write("<td class=\"FieldComponent\">") ;
73            renderUIComponent(component) ;
74            writer.write("</td>") ;
75          } else {
76            writer.write("<td class=\"FieldComponent\" colspans=\"2\">") ;
77            renderUIComponent(component) ;
78            writer.write("</td>") ;
79          }
80          writer.write("</tr>") ;
81        }
82      }
83      writer.write("</table>") ;
84      writer.write("</fieldset>") ;
85      writer.write("</div>") ;
86    }
87  }