KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > renderer > xhtmlmp > SimpleFormRenderer


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.faces.core.renderer.xhtmlmp;
6
7 import java.io.IOException JavaDoc;
8 import java.util.Enumeration JavaDoc ;
9
10 import javax.faces.component.UIComponent;
11 import javax.faces.context.FacesContext;
12 import javax.faces.context.ResponseWriter;
13
14 import javax.portlet.* ;
15 import org.exoplatform.faces.core.component.UIGrid;
16 import org.exoplatform.faces.core.component.UISimpleForm;
17 import org.exoplatform.faces.core.component.model.FormButton;
18 import org.exoplatform.faces.core.event.ExoActionEvent;
19
20
21 public class SimpleFormRenderer
22     extends org.exoplatform.faces.core.renderer.html.SimpleFormRenderer {
23   final static private String JavaDoc PREFIX_ACTION = ACTION + "." ;
24
25     public void decode(FacesContext context, UIComponent component ) {
26         UISimpleForm uiForm = (UISimpleForm) component ;
27         PortletRequest request = (PortletRequest)context.getExternalContext().getRequest() ;
28         Enumeration JavaDoc names = request.getParameterNames() ;
29         while (names.hasMoreElements()) {
30             String JavaDoc name = (String JavaDoc) names.nextElement();
31             if (name.startsWith(PREFIX_ACTION)) {
32                 String JavaDoc userAction = name.substring(PREFIX_ACTION.length(), name.length()) ;
33                 uiForm.setUserAction(userAction) ;
34                 uiForm.broadcast(new ExoActionEvent(uiForm, userAction, request.getParameterMap())) ;
35                 return;
36             }
37         }
38     }
39     
40     public void renderFormButton(FormButton button, ResponseWriter w, UIGrid uiParent) throws IOException JavaDoc {
41       w.write("<input type='submit'");
42       String JavaDoc clazz = button.getClazz() ;
43       if (clazz != null) {
44         w.write(" class='"); w.write(clazz); w.write("'");
45       }
46       w.write(" name='"); w.write(PREFIX_ACTION); w.write(button.getAction()); w.write("'");
47       w.write(" value='"); w.write(getLabel(button.getLabel())); w.write("'/>");
48     }
49   
50   protected String JavaDoc getScript(UISimpleForm uiForm) {
51     return "" ;
52   }
53   
54   public String JavaDoc getLabel(String JavaDoc label) {
55    if(label.indexOf("<img") >= 0) {
56      String JavaDoc[] temp = label.split("<img.*>") ;
57      label = "" ;
58      for(int i = 0 ; i < temp.length; i++) {
59        label += temp[i];
60      }
61    }
62    return label ;
63  }
64 }
Popular Tags