I'm developing a data-centric Web Application using JSF 2.1 and PrimeFaces 3.4.
As a result of a specific query, I must display the results in a bi-dimensional data table with some dynamic columns (imagine a sort of Pivot-table).
Currently I use a PrimeFaces <p:dataTable> with some standard <p:column> tags and a <p:columns> for the dynamically-created columns. The table is backed by a #ViewScoped Managed Bean.
It works fine, but:
Just like a pivot-table, I need to display multiple headers too, in
order to group some fields together. Unfortunately, <p:columns> is
not compatible with <p:columnGroup> (nor with many other features
like resizing etc.)
I need to display some custom sub-total rows (is there a way to
do this?)
I was thinking about populating the entire <p:dataTable> programmatically, but I can't use binding="#{...}" with a #ViewScoped bean due to JSF issue 1492.
Related
I am using Myfaces 2.1.9 and webflow 2.4.1M. I get a null pointer exception when trying to sort a datatable that is included by a dynamic include in my page.
I have a page that has a dynamic include:
Main xhtml page:
<ui:include src="..#{config.getIncludeName[bean.selectBox.selected]}.xhtml" />
I have 6 of these includes that can be switched using a select box. Each of these includes include a custom primefaces table (but they have the same ID, to the user it looks like it's the same table, but with different data, it's a different "form", if that makes sense). I want to change include by using the selectbox and then want to sort the table.
The decode phase is run, sortColumn is set on the datatable. But when the encode phase is run, the memory reference of the datatable is different from the datatable instance in the decode phase. The sortColumn is null in the encode phase, causing a null pointer exception to be thrown when the sorting is made.
This happens when the view is going to be rendered, in the buildView method in the FaceletViewDeclaration class. Seems like it builds the view again and when that happens the datatable component is reset.
Anyone know what might be the problem? Am I maybe using JSF in a way that I'm not supposed to?
Is it possible to use OmniFaces <o:validateAllOrNone> (which is pretty cool ;)) within an <ui:repeat> or <h:dataTable>?
I need a table with each row having an input field column. You could either fill in none of these values or all of them.
If I put the <o:validateAllOrNone> within the <ui:repeat> or <h:dataTable> and use the id of the input field in components attribute, then the validator also gets triggered, if all fields are empty.
No, that's not possible. The components attribute must refer physically multiple components, not a single component which is rendered multiple times. It can however be used on physically multiple components which are rendered during same iteration round. The <o:validateXxx> multi field validator is not designed to reference a single component which is rendered multiple times. The only OmniFaces validator which does that is <o:validateUniqueColumn>.
If you want to use the <o:validateXxx> multi field validator on dynamic inputs based on a collection, then your best bet is to use JSTL <c:forEach>. It will build physically multiple components.
E.g.
<c:forEach items="#{bean.items}" var="item" varStatus="loop">
<h:inputText id="input_#{loop.index}" value="#{item.value}" />
</c:forEach>
Assuming that there are 3 items, this will dynamically create JSF components with IDs of input_0, input_1 and input_2. Then you can just use <o:validateXxx> as follows (put it outside the loop!)
<o:validateAllOrNone components="input_0 input_1 input_2" />
You can replace the hardcoded string in the above example by an EL expression which returns the desired space separated string of component IDs from a backing bean.
<o:validateAllOrNone components="#{bean.inputIds}" />
An alternative would be to create a <x:validateAllOrNoneColumn> yourself or to post an enhancement request at OmniFaces issue tracker. It would be not exactly trivial to alter the existing <o:validateAllOrNone> that a completely separate component is desired.
I am trying to create a editable datatable whose values are java.util.Set. But in JSF-2.0 and 2.1 this is not possible as explained in Displaying objects from a Set collection in Datatable JSF does not work.
Till now as a work around all Sets are converted to java.util.List and everything works.
As mentioned in answer to var is the collection, not the item, I am trying Omnifaces #{of.setToList} so that I can avoid unnecessary conversion of Set to List. Everything works well when its a normal datatable. But when I tried to convert it to editable datatable, it doesnt work. So, is it possible to create editable datatable using Omnifaces #{of:setToList}?
Maybe I am doing something wrong. I can post code if needed. Thanks in advance.
An MVC 2 C# .NET 4.0 project with Entity Framework contains a view with a user control displaying a Telerik MVC Extensions grid. The grid uses one table with many fields and displays correctly.
When editing the grid rows, many of the fields need to be drop-down lists. To create them, I need to annotate the fields in my table with uihint; this uses a editor template that is my drop down list.
There are 13 data annotations for fields for the table object. Due to these annotations, the grid renders very slowly. What can be done to optimize this?
I need an iterating component like a <h:datatable> which generates <div> elements on every iteration and adds pagination. Something like an <ui:repeat> with pagination.
Does it exist in PrimeFaces or any other library?
I think the p:dataTable element in PrimeFaces does what you want. It draws a pagination panel with first/prior/next/last control semantics. Here is the example for pagination.
What I recommend most is their "lazy data table loading" mode where you do not transfer any data from the server to the client that is not actually going to be displayed. In this way you can handle a data source with millions of records. Here is the example for lazy data loading.
If you want a grid and not a table, I think the PrimeFaces p:dataGrid implementation is the best in the business. Unfortunately my own application doesn't use it, but the example is here.