0
votes

I would like to build a new component on the basis of PrimeFaces Tab/Tabview components. It should look like an add tab in a browser and open a page for filling out a form. The problem is that I want to integrate it in a TabView based on a data model (http://www.primefaces.org/showcase/ui/tabviewModel.jsf). Right now I can either combine a tab for filling out a form with a tab with predefined data or use a TabView, which dynamically creates tabs for my data.

I have read JSF documentation about creating custom components in two ways - as composite component or as a new Java class. I tried to create a custom component but it does not seem to work the way I described beyond.

My questions are:

1) is it possible to solve this problem with a composite component? If yes, could someone give me a hint?

2) if not, is there a tutorial for writing a new component on the basis of existing PrimeFaces component (presumably new sort of TabView)?

UPD: After doing some research I realized that the easiest way is writing a new renderer for TabView.

I declared a new renderer class:

public class AddableTabViewRenderer extends TabViewRenderer

and registered it in faces-config.xml:

<render-kit>
  <render-kit-id>HTML_BASIC</render-kit-id> 
  <renderer>
    <component-family>org.primefaces.component</component-family>
    <renderer-type>org.primefaces.component.TabView</renderer-type>
    <renderer-class>
      de.idealo.evaluation.jsf.webapp.component.AddableTabViewRenderer
    </renderer-class>
  </renderer>
</render-kit>   

However, when a view with TabView component is rendered, the encodeEnd method of TabViewRenderer is called, not the overriden method of AddableTabViewRenderer. Can you give me a hint about where the problem might be?

1

1 Answers

0
votes

The renderer-class is wrong in my configuration. I misunderstood the instructions about registering a component. I thought that render-type is the class that will be rendered with the custom renderer. It must be org.primefaces.component.TabViewRenderer instead. Now it works fine :)