1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.sys.document.web.renderers;
17  
18  import java.io.IOException;
19  
20  import javax.servlet.jsp.JspException;
21  import javax.servlet.jsp.JspWriter;
22  import javax.servlet.jsp.PageContext;
23  import javax.servlet.jsp.tagext.Tag;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.kuali.ole.sys.document.web.util.RendererUtil;
27  import org.kuali.rice.core.api.util.KeyValue;
28  
29  
30  
31  
32  public class RadioButtonGroupRenderer extends FieldRendererBase {
33  
34      
35  
36  
37  
38      public void render(PageContext pageContext, Tag parentTag) throws JspException {
39          JspWriter out = pageContext.getOut();
40          
41          try {
42              out.write(buildRadioButtons());
43              renderQuickFinderIfNecessary(pageContext, parentTag);
44              if (isShowError()) {
45                  renderErrorIcon(pageContext);
46              }
47              RendererUtil.registerEditableProperty(pageContext, getFieldName());
48          }
49          catch (IOException ioe) {
50              throw new JspException("Difficulty rendering radio buttons", ioe);
51          }
52      }
53  
54      
55  
56  
57  
58  
59      protected String buildRadioButtons() {
60          StringBuilder radioButtons = new StringBuilder();
61          for (Object keyLabelPairAsObject : getField().getFieldValidValues()) {
62              radioButtons.append(buildRadioButton((KeyValue)keyLabelPairAsObject));
63          }
64          return radioButtons.toString();
65      }
66      
67      
68  
69  
70  
71  
72  
73      protected String buildRadioButton(KeyValue keyLabelPair) {
74          StringBuilder radioButton = new StringBuilder();
75          
76          radioButton.append("<input type=\"radio\"");
77          
78          if (getField().getPropertyValue().equalsIgnoreCase(keyLabelPair.getKey().toString())) {
79              radioButton.append(" checked=\"checked\"");
80          }
81          
82          radioButton.append(" title=\"");
83          radioButton.append(this.getAccessibleTitle());
84          radioButton.append("\"");
85          
86          radioButton.append(" name=\"");
87          radioButton.append(getFieldName());
88          radioButton.append("\"");
89          
90          radioButton.append(" id=\"");
91          radioButton.append(getFieldName()+"_"+keyLabelPair.getKey().toString().replaceAll("\\W", "_"));
92          radioButton.append("\"");
93          
94          radioButton.append(" value=\"");
95          radioButton.append(keyLabelPair.getKey());
96          radioButton.append("\"");
97          
98          String onBlur = buildOnBlur();
99          if (!StringUtils.isBlank(onBlur)) {
100             radioButton.append(" ");
101             radioButton.append(onBlur);
102         }
103         
104         radioButton.append(" /> ");
105         radioButton.append(keyLabelPair.getValue());
106         radioButton.append(" ");
107         
108         return radioButton.toString();
109     }
110 
111     
112 
113 
114 
115     public boolean renderQuickfinder() {
116         return false;
117     }
118     
119 }