How to override h:selectOneRadio renderer? Where is the renderer class in jsf-impl?

前端 未结 2 921
囚心锁ツ
囚心锁ツ 2020-12-04 02:37

Is it possible to override renderer used by ? I tried to find the class from jsf-impl package of JSF 2.2 but didn\'t find it. The reason

2条回答
  •  情书的邮戳
    2020-12-04 02:41

    I added

      
            
                javax.faces.SelectOne
                javax.faces.Radio
                com.sial.ecommerce.configurator.ui.model.RadioRendererWithoutDataTable
            
        
    

    to faces-config.xml.

    And created a class which extends com.sun.faces.renderkit.html_basic.RadioRenderer And I did override the method encodeEnd then commented out the code which adding table elements.

    public class RadioRendererWithoutDataTable extends com.sun.faces.renderkit.html_basic.RadioRenderer {
        @Override
        public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
    
            rendererParamsNotNull(context, component);
    
            if (!shouldEncode(component)) {
                return;
            }
    
            ResponseWriter writer = context.getResponseWriter();
            assert (writer != null);
    
            String alignStr;
            Object borderObj;
            boolean alignVertical = false;
            int border = 0;
    
            if (null != (alignStr = (String) component.getAttributes().get("layout"))) {
                alignVertical = alignStr.equalsIgnoreCase("pageDirection");
            }
            if (null != (borderObj = component.getAttributes().get("border"))) {
                border = (Integer) borderObj;
            }
    
            Converter converter = null;
            if (component instanceof ValueHolder) {
                converter = ((ValueHolder) component).getConverter();
            }
    
    //      renderBeginText(component, border, alignVertical, context, true);
    
            Iterator items = RenderKitUtils.getSelectItems(context, component);
    
            Object currentSelections = getCurrentSelectedValues(component);
            Object[] submittedValues = getSubmittedSelectedValues(component);
            Map attributes = component.getAttributes();
            OptionComponentInfo optionInfo = new OptionComponentInfo((String) attributes.get("disabledClass"),
                    (String) attributes.get("enabledClass"), (String) attributes.get("unselectedClass"),
                    (String) attributes.get("selectedClass"), Util.componentIsDisabled(component), isHideNoSelection(component));
            int idx = -1;
            while (items.hasNext()) {
                SelectItem curItem = items.next();
                idx++;
                // If we come across a group of options, render them as a nested
                // table.
                if (curItem instanceof SelectItemGroup) {
                    // write out the label for the group.
                    if (curItem.getLabel() != null) {
    //                  if (alignVertical) {
    //                      writer.startElement("tr", component);
    //                  }
                        //writer.startElement("td", component);
                        writer.writeText(curItem.getLabel(), component, "label");
    //                  writer.endElement("td");
    //                  if (alignVertical) {
    //                      writer.endElement("tr");
    //                  }
    
                    }
    //              if (alignVertical) {
    //                  writer.startElement("tr", component);
    //              }
    //              writer.startElement("td", component);
    //              writer.writeText("\n", component, null);
    //              renderBeginText(component, 0, alignVertical, context, false);
                    // render options of this group.
                    SelectItem[] itemsArray = ((SelectItemGroup) curItem).getSelectItems();
                    for (int i = 0; i < itemsArray.length; ++i) {
                        renderOption(context, component, converter, itemsArray[i], currentSelections, submittedValues, alignVertical, i,
                                optionInfo);
                    }
    //              renderEndText(component, alignVertical, context);
    //              writer.endElement("td");
    //              if (alignVertical) {
    //                  writer.endElement("tr");
    //                  writer.writeText("\n", component, null);
    //              }
                } else {
                    renderOption(context, component, converter, curItem, currentSelections, submittedValues, alignVertical, idx, optionInfo);
                }
            }
    
            //renderEndText(component, alignVertical, context);
        }
    

    Then it worked for me.

    When I given

    
    
    
    
    

    in my jsf page.

    It converted to

    
    
    
    

    which was what I need.

提交回复
热议问题