Sorting panelgrid JSF - jsf

Can we sort values in column of a panelGrid. If yes, can I see an example

Rather use h:dataTable to represent a dynamic table which is backed by a List<RowObject>, wherein RowObject is basically just a Javabean (DTO - Data Transfer Obejct, VO - Value Object, whatever you call it :) ) representing a single row.
Such a List can be sorted using Collections#sort(). All you need to do is to implement a Comparator which takes care about the ordering. Then in the JSF page just have a bunch of buttons or links which calls Collections#sort() on the List. Those buttons/links just have to pass the sortfield along.
You can find here a basic example: http://balusc.blogspot.com/2006/06/using-datatables.html#SortingDatatable

No, you can't. <h:panelGrid> = <table>
If you want sorting, look at Richfaces or another component framework (Icefaces, primefaces, trinidad, tomahawk, etc). There are <x:dataTable> components there which allow sorting on their <x:colum>.

Related

Primefaces MultiSelectListBox

Is there a way to get SelectItemGroup values so that the entire trace of the SelectItem is contained in the value passed to the bean from the view? I have two SelectItemGroups and one SelectItem, but need the values contained in the SelectItemGroups as well.
It does not seem this is possible but would be a great feature. I used a Datatable instead but the MultiListBox would have been more elegant.

JSF ui:repeat vs h:dataTable

Before asking this question, I visited many other related ones and tried to gather the maximum of information. But, what I found till now let me understand that there is no real/major difference between ui:repeat and h:dataTable, and that whenever we can use h:dataTable we can also use ui:repeat (sometimes one of them is a little complex than the other, but at the end we got same results).
So, is there any use cases where the only choice is to use h:dataTable? or the opposite (only choice is ui:repeat)?
is there any use cases where the only choice is to use h:dataTable?
If you want to use an UIData-based component (with all of its special attributes absent in UIRepeat).
If you want to render a HTML <table> by a JSF component.
If you want to be able to customize the <table> rendering (like PrimeFaces <p:dataTable> does with sorting, filtering, grouping, folding, lazyloading, etc, etc).
If you aren't using Facelets as view technology.
or the opposite (only choice is ui:repeat)?
If you don't want any of above and thus need a pure markup-less iteration component.
If you want to be able to skip every n items during iteration (using step attribute).

Pagination for ArrayList in JSF2

I have one searched arraylist that i am getting from Database for that array list i want to apply paginataion with links First, Prev, Next, Last and Goto page dropdown here i don't want to call database for every request(i.e First,Prev,etc) i want to use arrylist that returned at the time of search.And one more requirement is field level sorting need to do Ascending,descending if user clicks on header field.can any one help me to fix this i want to use only JSF2 no RichFaces,etc
Thank in advance.
Why do you not want to use rich or prime faces or others? Just use primefaces datatable with paginator="true".
If you don't want it, but want to do it the hard way. I suggest you fetch everything from database. Use a datatable and in the getter of that table, you only give back a portion of your array. (index 10 to 20, or index 20 to 40 or...)
On top or bottom of your datatable you put some outputlinks. These can set the indexes you want to retrieve.
Hope my explanation is clear.
In case Myfaces Tomahawk is an option for you...
I see it (Myfaces Tomahawk) as a bit different from PrimeFaces/Richfaces cause MyFaces are responsible for the MyFaces JSF Implementation as well (so it could be an excuse for using Myfaces Tomahawk), so you can use the Myfaces JSF implementation + Myfaces Tomahawk
Take a look at the Myfaces Tomahawk datascroller

JSF input component for string lists?

I'm looking for a ready made, freely available component that provides the following features:
editing list entries
deleting entries
adding a new entry - possibly invoked multiple times
bind to property in managed bean of type List, or similar
optional: reordering entries
optional, simple: allow verification that at least one element is entered (required="true"? required="1"?)
optional, better: restrict by minimum and maximum allowed number of elements
The simplest way to allow editing entries would be to represent them as input element. Preferably the element won't need to sync to the server for every change in the number of elements.
Alternatively: is there a trivial way to create or compose such a component oneself?
If this if of importance: currently I'm using Richfaces 3.3.3 and MyFaces 2.0.
Edit: The component is expected mostly to be used for creating new lists from scratch, so that should be as simple for the user as possible. Preferably just tabbing to the next empty input element automatically created at the end of the list. I'd like to use the component for editing these lists, too, but that feature is expected to be used much less often.
You could take a look at Primefaces p:collector. The example in the Primefaces showcase is a good starting point. It can be used for adding elements to a list and for editing and removing these elements.
Probably the simplest way that I would know of going about almost all of these is the PrimeFaces dataTable component. With the exception of adding and deleting entries inline, all of this comes out of box. Deleting entries can be as simple as adding a delete button in a row and adding entries can be done through invoking a modal dialog with a form to create a new entry, add it to the backing bean list for the table, then asynchronously updating the dataTable.
http://www.primefaces.org/showcase/ui/datatableHome.jsf
It really does seem to be the most fully featured JSF dataTable component out there.

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

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.

Resources