1 5 package org.exoplatform.faces.core.renderer.xhtmlmp; 6 7 import java.io.IOException ; 8 import java.util.Enumeration ; 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 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 names = request.getParameterNames() ; 29 while (names.hasMoreElements()) { 30 String name = (String ) names.nextElement(); 31 if (name.startsWith(PREFIX_ACTION)) { 32 String 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 { 41 w.write("<input type='submit'"); 42 String 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 getScript(UISimpleForm uiForm) { 51 return "" ; 52 } 53 54 public String getLabel(String label) { 55 if(label.indexOf("<img") >= 0) { 56 String [] 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 |