Custom components in JSF - what about sub-components (children) - jsf

When Im creating custom component in JSF do I have to create all sub-components in that same way?
For example:
h:dataTable component use h:column to determinate column parameters
Now if I want to create dataTable component do I have to implement in that same way a column component?
(PS. "that same way" mean:
create DataTable class extends i.e. UIOutput
create DataTableTab class extends UIComponentELTag
append configuration to
custom.taglib.xml

In general the answer is no. If you create a complex component like a datatable, it can simply take advantage of the existing components for defining columns.
As the designer of such a dataTable, you are the one who determines what's needed. The standard column afaik has no knowledge of the dataTable, but the dataTable has knowledge about the columns.
Also note that you don't often need to create tag classes. This is only needed for JSP compatibility, but as JSP is deprecated I would advise you to not support it unless you really have to.

Related

How to specify the type of wrapper for JSF custom component?

I need to create the custom component as SelectOneRadio, but it should not has wrapper <table> But, <ul>, <li> for example. How I can specify the type of wrapper, ul, table or something else, when creating JSF custom components?
There seems to be a conceptual misunderstanding. There's no such thing as "wrapper" in this context. HTML is just generated by the Renderer associated with the UIComponent. If you'd like to change the generated HTML representation, just supply your own custom Renderer.
That said, it's advisable to learn JSF by a decent book so that you get the basic concepts properly right from the beginning on. Creating custom components is already covered in such a book.
See also:
How to override h:selectOneRadio renderer? Where is the renderer class in jsf-impl?
How do I determine the renderer of a built-in component

jsf 1.2 UI Component tag backing bean

I am using JSF 1.2 and I want to create a custom component using ui:component tag. I need to use this component in many places in my application, so I want this component to be highly reusable.
The problem is that for each use of this custom component I need a backing bean to store my information and act as action listener for certain events. I use this component in about 15 places within my application, and I also use this component more than once within a single page.
I don't want to create a custom JSF component (with UIComponent, renderer etc) and I don't know how to manage the backing data.
Is there any way I can specify a class, and the custom component creates an instance of the class each time I use it?
Edit:
Is it possible to extend an existing JSF component? (I use Richfaces implementation)
Any help or idea are welcome.

Remove auto generated j_id from composite components

I'm loving the jsf 2.0 composite component setup. One other thing I love is prependId="false" on forms. Is there an equivalent that can be defined in cc:interface or cc:implementation that will prevent jsf from creating a j_id to prepend to the ids defined within the composite component?
That's not possible. Just give the component a fixed id instead letting JSF autogenerate one. The same applies on forms by the way. This way you can still select them using CSS selectors.
Or better, just give them a styleClass so that you don't need to select by ID, for the case that this aversion was actually caused by inability to select components/elements by client ID (I don't see other feasible reasons).

How to use Component class in JSF2

I'm developing custom jsf2 component, that has an datasource attribute. There are some operations on datasource, that belongs to VIEW. For instance, there is a method that returns some image for column header, if the table is sorted by the column, and other image if it doesn't. In JSF1, each component has its Java class, extending UIComponent, so I can implement such methods there. However, I see that in JSF2, component class is created automatically from xhtml, so I doesn't know how to add methods to it. Can anybody explain me how to do it? s it possible to use both composite component and component class in one component?
In JSF 2 you can create component classes in Java in the same way you do in JSF 1 (the API may have changed a bit, but it is mostly the same. For example, look at http://weblogs.java.net/blog/driscoll/archive/2009/10/09/jsf-2-custom-java-components-and-ajax-behaviors

Extend Richfaces components - for example customize Datatable component for specific implementation

How to extend the functionality of Richfaces components for example Data table with custom header and sorting techniques. i have seen extended data table but did not get much information from it. Please point me to an example if at it is available.
Thanks
Soma
Well, you can extend a JSF component with the regular java extension (extends). You will have to extend a number of classes, depending on the exact component:
UIComponentName/HtmlComponentName
HtmlComponentNameRenderer
ComponentNameTag
and you might need to register the renderer in faces-config.xml.
You can take a look at this thread, or google for "Extend JSF component" or "Create custom JSF component".

Resources