1 5 6 package org.exoplatform.portlets.portletregistery.renderer.html; 7 8 9 import javax.faces.component.UIComponent; 10 import javax.faces.context.FacesContext; 11 import javax.faces.context.ResponseWriter; 12 import org.exoplatform.faces.FacesConstants; 13 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer; 14 import org.exoplatform.portlets.portletregistery.component.UIPortletList; 15 import org.exoplatform.services.portletcontainer.pci.PortletData; 16 import java.io.IOException ; 17 import java.util.Iterator ; 18 import java.util.Map ; 19 import java.util.ResourceBundle ; 20 import java.util.Set ; 21 22 27 public class AddPortletRenderer extends HtmlBasicRenderer { 28 private static String SCRIPT = 29 "<script>\n" + 30 "function submitAddPortletForm(action) {\n" + 31 " document.portletForm.elements['"+FacesConstants.ACTION +"'].value = action ;\n" + 32 " document.portletForm.submit();\n" + 33 "}\n" + 34 "</script>\n" ; 35 36 final public void encodeChildren(FacesContext context, UIComponent component ) throws IOException { 37 UIPortletList uiPortletList = (UIPortletList) component ; 38 ResourceBundle res = getApplicationResourceBundle(context.getExternalContext()) ; 39 ResponseWriter w = context.getResponseWriter() ; 40 String baseURL = uiPortletList.getBaseURL(context); 41 Map allPortletMetaData = uiPortletList.getAllPortletMetaData() ; 42 Set keys = allPortletMetaData.keySet(); 43 w.write("<center>") ; 44 w. write("<form name='portletForm' action='"+baseURL+"' method='post'>") ; 45 w. write("<input type='hidden' name='"+ FacesConstants.ACTION +"' value=''/>"); 46 w. write("<table cellspacing='1' cellpadding='3'>"); 47 w. write("<tr>"); 48 w. write("<th colspan='3'>"); 49 w. write(res.getString("UIPortletList.header.title")) ; 50 w. write("</th>"); 51 w. write("</tr>"); 52 Iterator i = keys.iterator() ; 53 while(i.hasNext()) { 54 String key = (String ) i.next() ; 55 PortletData portlet = (PortletData) allPortletMetaData.get(key) ; 56 String portletTitle = portlet.getPortletName() ; 57 String portletDescription = portlet.getDescription("en") ; 58 if(portletDescription == null) portletDescription = "N/A" ; 59 w. write("<tr>") ; 60 w. write("<td width='10'>") ; 61 w. write("<input style='width: 15px' type='checkbox' name='portletId'" + 62 " value='" + key +"'/>") ; 63 w. write("</td>"); 64 w. write("<td>") ; 65 w. write(portletTitle) ; 66 w. write("</td>") ; 67 w. write("<td style='padding: 2px 20px 2px 10px'>") ; 68 w. write(portletDescription) ; 69 w. write("</td>") ; 70 w. write("</tr>"); 71 } 72 w. write("<tr>"); 73 w. write("<td align='center' colspan='3'>") ; 74 w. write("<a HREF=\"javascript:submitAddPortletForm('"+SAVE_ACTION +"');\">"); 75 w. write(res.getString("UIPortletList.button.save")); 76 w. write("</a> "); 77 w. write("<a HREF=\"javascript:submitAddPortletForm('"+CANCEL_ACTION +"');\">"); 78 w. write(res.getString("UIPortletList.button.cancel")); 79 w. write("</a>"); 80 w. write("</td>") ; 81 w. write("</tr>"); 82 w. write("</table>"); 83 w. write(SCRIPT); 84 w. write("</form>"); 85 w.write("</center>"); 86 } 87 } | Popular Tags |