I would like to have an ace:datatable where I can compare an "old" object against a "new" object.
Unfortunately I can only use List of Object to handle only one Object per row. Is it possible to handle more than one object per row?
If both lists will have always the same size you could try something like this.
<ace:dataTable value="#{bean.oldList}" var="item" rowIndexVar="index">
<ace:column headerText="Old Value">
<h:outputText value="#{item.value}"/>
</ace:column>
<ace:column headerText="New Value">
<h:outputText value="#{bean.newList[index].value}"/>
</ace:column>
</ace:dataTable>
However i don't really like this because it can lead to index out of bound exception
Perhaps you could also try playing with nested datatables.
Related
Is it possible to flip datatable in primefaces, in order to have headers in the left not in the top?
I have following table:
<p:dataTable value="#{rolesMgmt.listOfMapsRoles}" var="map" id = "dataTable">
<p:columns value="#{rolesMgmt.columns}" var="column">
<f:facet name="header">
<h:outputText value="#{column.header}" />
</f:facet>
<h:outputText value="#{map[column.property]}" />
</p:columns>
</p:dataTable>
As you see, I have a lot of headers and 2-3 rows and I need to flip this table
No this is not possible by using some attribute on the p:dataTable itself. For this to be achieved you need to transpose your model. Maybe you can achieve something by manipulating the responsiveness. But if you have lots of columns AND lots of rows, maybe you should think of just displaying a 'summary' in a datatable and have a details view.
Or use a p:datagrid (showcase) where you can sort of free-format your records or a plain ui:repeat? Since you do not seem to need sorting/filtering etc in this case. The p:datatable seems overkill to me now
It's not possible to flip the table.
Why don't you take a look to the ColumnToggler?
You can temporarly reduce the width of the table and then, on demand, add other columns.
I'm trying to dynamically display the columns of a p:dataTable: the server dictates which columns are displayed and in which order. It doesn't look like I can set a dynamic order using the regular p:column tag so I'm stuck using the p:columns tag. The problems with the p:columns tag are:
1) The example in the showcase shows it working with String data, where you can map a column name to a field and then use an expression language map to retrieve the data (like a pseudo-getter)
http://www.primefaces.org/showcase/ui/data/datatable/columns.xhtml
If I have different data types though, then I'm probably stuck with a bunch of panels with render attributes based on the type of the data (display Strings one way, display User objects another way, etc).
Example:
<p:dataTable value="#{myBean.rows}" var="row">
<p:columns value="#{myBean.columns}" var="column">
<f:facet name="header">
<h:outputText value="#{column.header}" />
</f:facet>
<!-- The content of the cell is dynamic based on the type of the field -->
<!-- display a String field -->
<h:outputText rendered="#{myBean.isStringType(column.header)}"
value="#{row[column.property]}"/>
<!-- display a Person field -->
<h:outputText rendered="#{myBean.isPersonType(column.header)}"
value="#{row[column.property].name}, #{row[column.property].email}"/>
</p:columns>
</p:dataTable>
2) p:columns only supports a single sortFunction/filterFunction for all columns. Since these columns all have different types of data, they will require many different sorting and filtering methods
A p:column easily allows for the display of different data types as well as the sorting/filtering of the data. The only thing it can't do is have a dynamic order.
Unless I'm missing something? Is there a way to get this to work with p:column ? Or is there an elegant way to have p:columns handle all of this?
It doesn't look like I can set a dynamic order using the regular p:column tag so I'm stuck using the p:columns tag.
If the #{myBean.columns} columns model is constant during at least the view scope, then you'd better use <c:forEach><p:column><c:choose>. It's faster than <p:columns>+rendered, and allows more dynamic freedom as you can declare every <p:column> individually depending on the type instead of having only one <p:columns> whose state changes every iteration round.
<p:dataTable value="#{myBean.rows}" var="row">
<c:forEach items="#{myBean.columns}" var="column">
<c:choose>
<c:when test="#{column.type eq 'STRING'}">
<p:column sortBy="#{row[column.property]}" filterBy="#{row[column.property]}">
#{row[column.property]}
</p:column>
</c:when>
<c:when test="#{column.type eq 'PERSON'}">
<p:column sortBy="#{row[column.property].name}" filterBy="#{row[column.property].name}">
#{row[column.property].name}, #{row[column.property].email}
</p:column>
</c:when>
...
</c:choose>
</c:forEach>
</p:dataTable>
See also:
JSTL in JSF2 Facelets... makes sense?
How to create dynamic JSF form fields
How to use an Enum to filter in p:dataTable?
My approach looks like this:
<p:column filterBy="#{item.EMyEnum}" filterMatchMode="in" >
<f:facet name="filter">
<p:selectCheckboxMenu label="Select" onchange="PF('datatable').filter()">
<f:selectItems value="#{MyEnum.values()}" />
<p:ajax event="toggleSelect" onsuccess="PF('datatable').filter()"/>
</p:selectCheckboxMenu>
</f:facet>
<h:outputText value="#{item.EMyEnum}"/>
</p:column>
Everything looks fine, but when I select one item from the drop down, the whole content is filtered. When I deselect everything in the drop down, then the content comes up again, so basically the filter seems to work, but every comparison is evaluated to false. I do not understand why, as JSF has build in Enum-converters hasn't it? But what am I missing or doing wrong here?
I am working with PF 5.1 on Mojarra 2.1.29
I solved my problem with usage of a List of my Enum types in combination with the OmniFaces GenericEnumConverter. This works like charm, but I'd still like to know what exactly the problem with the previous solution is and how it could be fixed.
I need a converter with custom parameters, I've made it and it works well, except when I use it with row elements and I can't understand why, ideas?
Examples
This works well:
<h:outputText value="#{bean.value}">
<cc:converter param="#{bean.attribute}" />
</h:outputText>
also this one:
<h:outputText value="#{bean.value}">
<cc:converter param="fixedValue" />
</h:outputText>
this one doesn't work at all, param is null inside the converter:
<rich:dataGrid value="#{bean.list}" var="row">
<h:outputText value="#{row.value}">
<cc:converter param="#{row.attribute}" />
</h:outputText>
</rich:dataGrid>
See BalusC link. It describes why your converter doesn't work. Converter without parameters works fine inside datatable in JSF 1.2. For simulate conversion you can use getter method in object which represents row like getConvertedValue and move your code from converter into this method. After that in datatable you can call #{row.convertedValue} for displaying the converted value.
Primefaces 3.5 doesn't seem to filter data at all from the datatable, oddly enough it somehow reorders them as I type, so, there must be some AJAX calls firing, but obviously not the right ones.
<h:panelGroup id="table-wrapper-component">
<prime:dataTable
rendered="#{artifactSelectionBackingBean.visibleComps}"
value="#{artifactSelectionBackingBean.components}"
var="tagInfoObject" emptyMessage="No tags found with given criteria"
filteredValue="#{artifactSelectionBackingBean.filteredComponents}">
<prime:ajax event="filter" global="false" />
<prime:column sortBy="#{tagInfoObject.tagId}"
headerText="Identifier" filterMatchMode="contains" filterBy = "#{tagInfoObject.tagId}">
<h:outputText value="#{tagInfoObject.tagId}" />
</prime:column>
<prime:column sortBy="#{tagInfoObject.type.tagTypeId}"
headerText="Tag Identifier" filterMatchMode="contains" filterBy ="#{tagInfoObject.type.tagTypeId}">
<h:outputText value="#{tagInfoObject.type.tagTypeId}" />
</prime:column>
<prime:column sortBy="#{tagInfoObject.title}" headerText="Title" filterMatchMode="contains" filterBy="#{tagInfoObject.title}">
<h:outputText value="#{tagInfoObject.title}" />
</prime:column>
<prime:column filterBy="#{tagInfoObject.description}"
filterMatchMode="contains" sortBy="#{tagInfoObject.description}"
styleClass="wrap" headerText="Component Description">
<h:outputText value="#{tagInfoObject.description}" />
</prime:column>
</prime:dataTable>
</h:panelGroup>
Any help is appreciated! All the Beans and method calls exist and return the appropriate data, just that the filtering doesn't seem to work at all.
Also, note that sorting functions properly only filtering does not!
The issue was that you always need to wrap any filtering/sorting attributes in a data table with an h:form tag. This is not explicitly specified in the documentation of PrimeFaces, however, it is in the showcase here. I wrapped the whole thing in form tags.
So, don't forget to wrap your data tables in a form if you want any type of interaction provided by primefaces.
Your managed Bean Code will do a lot of good
Post your managed bean code.
May be you have not set the value for artifactSelectionBackingBean.filteredComponents in the managed bean