1 8 9 package org.exoplatform.portlet.faces.renderer; 10 11 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer; 12 import org.exoplatform.portlet.faces.component.UIPortletPreferences; 13 import org.exoplatform.portlet.faces.component.UIPreferencesForm; 14 15 import javax.faces.component.UIComponent; 16 import javax.faces.context.ExternalContext; 17 import javax.faces.context.FacesContext; 18 import javax.faces.context.ResponseWriter; 19 import java.io.IOException ; 20 import java.util.ResourceBundle ; 21 22 23 public class PortletPreferencesRenderer extends HtmlBasicRenderer { 24 25 static String DEFAULT_HELP_MESSAGE = 26 "Help message is not available. To customize this message, add the message to "+ 27 " the portlet resource properties file with the key: info.portlet-preferences-help-info"; 28 29 public void encodeBegin( FacesContext context, UIComponent component ) throws IOException { 30 UIPortletPreferences uiPrefs = (UIPortletPreferences) component ; 31 ExternalContext econtext = context.getExternalContext() ; 32 ResourceBundle res = getApplicationResourceBundle(econtext) ; 33 String helpMessage = DEFAULT_HELP_MESSAGE ; 34 try { 35 helpMessage = res.getString("info.portlet-preferences-help-info") ; 36 } catch (Exception ex) {} 37 38 ResponseWriter w = context.getResponseWriter() ; 39 w.write("<table class='portlet-preferences' border='0' cellspacing='2'>") ; 40 w. write("<tr>"); 41 w. write("<td>"); 42 addPreferencesForm(w, uiPrefs) ; 43 w. write("</td>"); 44 w. write("<td style='solid 1px black' valign='top'>"); 45 w.write(helpMessage) ; 46 w. write("</td>"); 47 w. write("</tr>"); 48 w.write("</table>"); 49 } 50 51 private void addPreferencesForm(ResponseWriter w, UIPortletPreferences uiPrefs) throws IOException { 52 UIPreferencesForm form = (UIPreferencesForm) uiPrefs.getChildComponentOfType(UIPreferencesForm.class); 53 w.write("<fieldset><legend>Preferences</legend>"); 54 FacesContext context = FacesContext.getCurrentInstance(); 55 form.encodeBegin(context); 56 form.encodeChildren(context); 57 form.encodeEnd(context); 58 w.write("</fieldset>"); 59 } 60 61 } 62 63 | Popular Tags |