KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlet > faces > renderer > PortletPreferencesRenderer


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

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 JavaDoc;
20 import java.util.ResourceBundle JavaDoc;
21
22
23 public class PortletPreferencesRenderer extends HtmlBasicRenderer {
24
25   static String JavaDoc 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 JavaDoc {
30     UIPortletPreferences uiPrefs = (UIPortletPreferences) component ;
31     ExternalContext econtext = context.getExternalContext() ;
32     ResourceBundle JavaDoc res = getApplicationResourceBundle(econtext) ;
33     String JavaDoc helpMessage = DEFAULT_HELP_MESSAGE ;
34     try {
35       helpMessage = res.getString("info.portlet-preferences-help-info") ;
36     } catch (Exception JavaDoc 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 JavaDoc {
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