I am currently trying to display a ResultSet in a h:dataTable in JSF.
Basically what I am doing is executing a SQL statement which can be inserted on the website and I want to display the result of that in a table.
I can not create model classes because the tables that are used are also dynamic.
The tricky part is the fact, that I do not know how many columns there are in the ResultSet, nor the datatypes(currently I am getting these from the ResultSetMetaData).
How would I go about displaying something with dynamic columns and column content(different datatypes) in a table on a website using JSF?
Thanks in advance.
Have a data structure like List<Map<String, Object>> results in your managed bean to store the results.
On UI side, use 2 nested ui:repeat elements instead of an h:dataTable.
Outer repeat will loop rows (results), inner repeat will loop columns (result.keySet()), each cell will get its value by result.get(fieldName).
Not-tested UI code:
<table>
<ui:repeat value="#{mb.results}" var="result">
<tr>
<ui:repeat value="#{result.keySet()}" var="fieldName">
<td>
#{result.get(fieldName)}
</td>
</ui:repeat>
</tr>
</ui:repeat>
</table>
Related
This is regarding a JavaEE web application which uses JSF, JPA and Primefaces.
In a large JSF page, a table needs to be populated by a list of items. The first column display the name of the items as an output label. The second column has an input text to record user input. The third column displays a value which is calculated considering several factors and take a relatively long time.
I want to display the page with data for the first two columns, but the third Colum data need to be filled after the complete page is displayed to the user. This is to minimize the user waiting a long time before starting the data entry. As the user starts seeing the page, the third column needs to be populated as the data is made available.
Is this possible to be achieved in JSF? If needed I can use OminiPages, but not technologies like Spring and Struts.
<table>
<ui:repeat id="rptItems"
value="#{clientEncounterComponentItemController.items}"
var="ii" >
<tr>
<td>
<p:outputLabel for="itStC" value="#{ii.name}" ></p:outputLabel>
</td>
<td>
<p:inputText id="itStC" value="#{ii.shortTextValue}" >
</p:inputText>
</td>
<td>
<h:panelGroup rendered="#{ii.displayLastResult}" >
<p:outputLabel id="lblResult" value="#{clientEncounterComponentItemController.findFormsetValue(ii)}" ></p:outputLabel>
</h:panelGroup>
</td>
</tr>
</ui:repeat>
</table>
I need to display components and data dynamically. Below code I am trying to populate list of select boxes. Trying to populate values from var within forEach.
<c:forEach items="${bean.dynamicParamsBean.editableComoBoxes}" var="editableComboBox">
<h:selectOneMenu value="#{editableComboBox.param}">
<f:selectItems value="#{editableComboBox.dataProvider}" />
</h:selectOneMenu>
</c:forEach>
This works fine except f:selectItems where my select box is not populating any data. editableComboBox.dataProvider returns list of SelectItem objects.
This exact code works fine if I don't use loop and in turn var, directly populating select box values by referencing to bean.
Is there any workaround and alternative to resolve this issue?
When I use just plain h:dataTable:
<h:dataTable var="office"
value="#{reportController.data}" width="100%"
id="titleRpt" styleClass="data" border="1" cellpadding="2"
columnClasses="none,rightAlign,rightAlign,rightAlign,rightAlign,rightAlign,rightAlign,rightAlign"
headerClass="tableHeader"
rowClasses="oddRow,evenRow"
cellspacing="0" rendered="#{reportController.doDisplay and reportController.reportType eq 'T'}">
I get the following output:
However, once I change h:dataTable to p:dataTable (same code except for the p), I get the following:
How do I get PrimeFaces to automatically set the column widths based on the data within (which is dynamic and retrieved from the DB)? I am using the smoothness theme.
The reason I have to go with the PrimeFaces version and not the plain JSF one is because I need to have data export functionality and p:dataExporter requires that it be nested inside a p:dataTable and not an h one.
I am using rich faces data table tag in my jsf:
<r:dataTable id="dataTable" var="user" preserveDataModel="false"
value="#{ListUsersManagedBean.users}" rows="10"
rowId="#{user.firstName}" rowKeyVar="index"
width="500" style="float:centre" reRender="ds" columnClasses="center">
Here i have configured rowsize as 10 in static way.I want to give the user a dropdown in the table so he can select number of rows 100,200,300,400 etc below the column.How can i do this.Or any better solution?
Thanks
You can do that by binding a variable to rows like rows = #{yourBean.noOfRows} and same to the combo box, and reRender your datatable onChange of comboBox.
This can be done if you are strict to use <rich:dataTable> or you can use jQuery datatable easy to integrate and easy to use for the functionality you need.
<h:dataTable width="100%" border="1" cellspacing="0"
cellpadding="2" style="border-collapse:collapse;display:block"
styleClass="Header" value="#{adminBean.displayResults}"
var="aResult" binding="#{adminBean.browseResultsHTMLDataTable}">
This is what i am trying to do. I have a dynamic list of data, which i try to display in the HTML Table format using h:dataTable (the bounded value is an arrayList). The table has got a radio button for each row it displays (boolean w/ h:selectOneRadio ) now when i select the radio button in one of these rows, i want to get the values of the row that is selected for which i try to use binding attribute. But i get Row Unavailable exception - is my approach wrong? any suggestions?
Selecting rows by radio button in a datatable is a tricky task since the radio buttons aren't grouped. Long story short: Select row by radio button.
I think you can use <t:selectOneRadio> with layout="spread" and then <t:radio> on each row.