I want to convert html table to primeface datatable, I have converted some more table in my project but below code is bit complex so I need your help, here columns are created using different list and rows are from different list.
<table >
<thead>
<tr >
<th style="width:45px;">Id</th>
<th>#{msg['manage.relationship.type.name']}</th>
<c:forEach items="#{manageRelationBean.languageList}" var="languageName" >
<th>#{languageName}</th>
</c:forEach>
<th style="width:75px;">#{msg['manage.relationship.action']}</th>
</tr>
</thead>
<tbody>
<c:forEach items="#{manageRelationBean.languageRelList}" var="languageRelDTO">
<tr>
<td>#{languageRelDTO.relationId}</td>
<td>#{languageRelDTO.relationName}</td>
<c:forEach items="#{languageRelDTO.languageList}" var="relationValues">
<td>#{relationValues.relationValue}</td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</html>
Have you looked at the Showcase example? http://www.primefaces.org/showcase/ui/datatableBasic.jsf
Here is something like your example, for the first few columns. Notice the ForEach within the datatable- This will allow dynamic columns like you have.
<h:form>
<p:dataTable var="languageRelDTO" value="#{manageRelationBean.languageRelList}">
<p:column headerText="Id">
<h:outputText value="#{languageRelDTO.relationId}" />
</p:column>
<p:column headerText="#{msg['manage.relationship.type.name']}">
<h:outputText value="#{languageRelDTO.relationName}" />
</p:column>
<c:forEach items="#{manageRelationBean.languageList}" var="languageName">
<p:column headerText="#{languageName}" />
<h:outputText value="#{languageRelDTO.languageList[languageName.index]}" />
</p:column>
</c:forEach>
</p:dataTable>
</h:form>
Didn't test it, but you should get the idea.
Related
I tried to decrease the height of the column by using following syntax:
<p:column style="height:10px;">
and the datatable row height won't decrease; it only increases if I set a bigger size.
Is there a way to make the height smaller than the default/existing one?
This is the exact code, that I'm using:
<c:forEach var="column" items="#{dispoFillingPage.columnListAuftrag}">
<c:choose>
<c:when test="${column.dateColumn}">
<p:column id="#{column.id}" filterStyleClass="#{column.filterStyleClass}" headerText="#{column.title}" visible="#{column.visible}"
width="#{column.width}" filterBy="#{data[column.property]}" sortBy="#{data[column.property]}" field="#{column.property}"
filterFunction="#{standortPage.filterByDate}" filterMatchMode="contains" style="height:10px">
<f:attribute name="rtcCol" value="#{column}" />
<h:outputText value="#{data[column.property]}">
<f:convertDateTime type="date" pattern="yyyy-MM-dd" />
</h:outputText>
</p:column>
</c:when>
<c:otherwise>
<p:column id="#{column.id}" filterStyleClass="#{column.filterStyleClass}" headerText="#{column.title}" field="#{column.property}"
visible="#{column.visible}" width="#{column.width}" filterBy="#{data[column.property]}" sortBy="#{data[column.property]}"
filterMatchMode="contains" style="height:10px;">
<f:attribute name="rtcCol" value="#{column}" />
<h:outputText value="#{data[column.property]}" />
</p:column>
</c:otherwise>
</c:choose>
</c:forEach>
I have to do this, because I have two datatables with 20 rows each and I have to make them fit in the screen, so that they are entirely visible to the user.
I had to decrease the font-style of the datatable in order to decrease also the row height.
<p:datatable style="font-size:8px">
But this way I decrease the entire datatable.
Hope somebody may give me a hint on this case, searched a lot before posting this question with no luck.
I have a datatable that allows only a single row selection (it may include 200 rows at a time), after one is selected, a commandButton redirects the user to a new form to display some information.
The problem rises when user first applies a filter in the datatable on any given column, selects a row and clicks the commandButton, my backing bean (#ViewScoped) receives no selected object (null)
Since the form is big, here i post just part of it to display the Datatable structure:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<h:body >
<h:form id="Form1">
<p:outputPanel id="ID1">
.
.
.
<table cellpadding="4" cellspacing="4" border="0" style="width: 100%;">
<tr>
<td><b><big><big><font face="Arial" >#{beanD.MenuTitle} > List of records </font></big></big></b></td>
<td>
<b><big><font face="Arial"><p:outputLabel value="|" /></font></big></b>
</td>
<td style="width: 150px;">
<p:commandButton style="font-family:Arial;font-size: 13px;" icon="ui-icon-check" value="Open Record" ajax="false"
actionListener="#{MBR.Method1(2,MBR.var1.cod,MBR.var1.codS)}" action="#{beanD2.url_Menu('FormRedirected')}"/>
</td>
</tr>
</table>
<table cellpadding="4" cellspacing="4" border="0">
<tr>
<td>
<p:dataTable var="Rad" selectionMode="single" value="#{MBSg.list}"
id="RSTable" widgetVar="RS" selection="#{MBR.var1}" rowKey="#{Rad.codS}"
style="font-family: Arial;font-size: 12px; height: 320px;" emptyMessage="No Records"
scrollable="true" scrollHeight="100%;" frozenColumns="1" styleClass="FirstCol" >
<p:column headerText="Header1" filterStyle="font-family:Arial;font-size: 12px;width:60px;" filterBy="#{Rad.field1}" filterMatchMode="contains" style="font-family:Arial;font-size: 12px;width: 60px;">
<h:outputText value="#{Rad.field1}" />
</p:column>
<p:column headerText="Header2" filterBy="#{Rad.field2}" filterMatchMode="contains" style="font-family:Arial;font-size: 12px;width: 250px;">
<h:outputText value="#{Rad.field2}" />
</p:column>
<p:column headerText="Header3" filterBy="#{Rad.field3}#{Rad.entidades}" filterMatchMode="contains" style="font-family:Arial;font-size: 12px;width: 900px;">
<h:outputText value="#{Rad.field3}" />
</p:column>
<p:column headerText="Header4" filterBy="#{Rad.field4}" filterMatchMode="contains" style="font-family:Arial;font-size: 12px;width: 100px;">
<h:outputText value="#{Rad.field4}" />
<p:column headerText="Header5" filterStyle="font-family:Arial;font-size: 12px;width:70px;" filterBy="#{Rad.field5}" filterMatchMode="contains" style="font-family:Arial;font-size: 12px;width: 120px;">
<h:outputText value="#{Rad.field5}" />
</p:column>
</p:dataTable>
</td>
</tr>
</table>
</p:outputPanel>
</h:form>
</h:body>
</html>
This is the method in my backing bean (MBR) that evaluates selection made by user (stored in variable var1 )
#ManagedBean(name = "MBR")
#ViewScoped
public class BeanR {
.
.
public void Method1(int proc, int num, int num_s) {
try {
if (var1 == null) {
mbT.setMens("No item Selected");
mbT.warn();
mbT.resetTable("Form1:RSTable");
..."some other operations performed"
} else {
Method2(proc, num, num_s);
}
} catch (ParseException e) {
mbT.setMens("Error in MBR : '" + this.getClass() + ".Method1()' caused by: " + e.getMessage());
mbT.error();
}
}
}
As mentioned before, if selection is made after filtering ( then commandButton clicked) this message is launched in my bean: mbT.setMens("No item Selected");
By the way, filtering works fine, not problems at all.
Application is developed using Primefaces 5.0 with no chance to upgrade right now
Any work around will be appreciated, i have googled and read PrimeFaces showcases but have not found any answer,
Best regards.
Last Update:
After lots of tests i figured out that DataTable's Attribute frozenColumns was the one causing this strange behaviour when table was filtered. Hopefully any expert in StackOverflow may give us a deeper insight on the reasons behind it.
As per my problem, after removing the attribute the datatable worked fine. Hope anyone finds this usefull in future.
I have encountered similar issue and finally figure out that I have missed the filteredValue attribute in the dataTable tag.
Add a rowKey as a property on p:dataTable component.
<p:dataTable value="#{myBean.cars}" var="car" rowKey="#{car.id}">
...
<p:dataTable>
I am using buttons in a p:datatable and they are triggering a p:blockUI (PF 6.0)
When located in the footer of my datatable, the button does trigger the blockUI. When moved into a column, it does not trigger it
BlockUI
<p:blockUI block="blockPanel"
trigger="myForm:myTable:myButton myForm:myTable:myButton2">
Loading..<br />
<p:graphicImage name="images/loading_blue.svg" />
</p:blockUI>
Datatable
<p:panel id="blockPanel">
<h:form id="myForm">
<h:panelGrid columns="1" cellpadding="5">
<p:dataTable id="myTable" value="#{modelBean.myList}" var="entry">
<!-- Some data -->
<p:column headerText="Name">
<h:outputText value="#{entry.name}" />
</p:column>
<!-- Does not work -->
<p:column style="text-align: center">
<p:commandButton id="myButton" actionListener="#{bean.method()}" />
</p:column>
<!-- Works -->
<f:facet name="footer">
<p:commandButton id="myButton2" actionListener="#{bean.method()}" />
</f:facet>
</p:dataTable>
</h:panelGrid>
</h:form>
</p:panel>
Why ?
The following workaround did not work for me:
<p:commandLink ... onclick="bui.show()" oncomplete="bui.hide()">
...
<p:blockUI widgetVar="bui" />
As a workaround, I used pe:blockUI:
http://www.primefaces.org/showcase-ext/sections/blockui/blockPage.jsf
What I mean : You don't have any value in your datatable. Put it one, you can create a backingBean return one value and add property value=#{myBean.value}. Also you have data on you datatable ! Test it
I met a problem for two days. nowhere I advance
my problem is to make a dynamic content in a panel according to the selected element in the list p: selectOneMenu
<h:outputLabel value="Categorie :" />
<p:selectOneMenu value="#{composantbean.selectedCategoryId}" required="true" >
<f:selectItem itemLabel="Select categorie" itemValue="" />
<f:selectItems value="#{composantbean.listcat}" var="cat" itemValue="#{cat.nomCat}" itemLabel="#{cat.nomCat}" />
<p:ajax update="panl" event="change" listener="#{composantbean.catListener()}"/>
</p:selectOneMenu>
<p:panel id="panl" header ="Caracteristique selon la categorie" toggleable="true" rendered="true" >
<h:panelGrid id="panlecart" columns="2" cellpadding="5" rendered="true">
<c:forEach items="#{composantbean.categorie.proprietes}" var="var">
<h:outputText value="#{var.nomProp}"/>
<h:inputText value="" />
</c:forEach>
</h:panelGrid>
</p:panel>
content appears this is true but unfortunately it is not synchronized is displayed shift
but if I use another <p: selectOneMenu id = "panel" content is displayed and synchronized
Haw can I fixe my prblem .Please and thank you in advance
As Lucas said, it is a bad idea using c:foreach (and all kind of JSTL) in JSF, especially with ajax.
Here are references you should read, to know more about JSTL in JSF:
JSTL in JSF2 Facelets... makes sense?
https://rogerkeays.com/jsf-c-foreach-vs-ui-repeat
Using ui:repeat in h:panelGrid is not recommended also. You may read the discussion here.
So, IMHO, you should try another approach, such as using dataTable, as stated in above link.
Or, you could use html's table tag (<table>) as replacement of h:panelGrid, with html's tr and td tag inside ui:repeat. For example:
<h:outputLabel value="Categorie :" />
<p:selectOneMenu value="#{composantbean.selectedCategoryId}" required="true" >
<f:selectItem itemLabel="Select categorie" itemValue="" />
<f:selectItems value="#{composantbean.listcat}" var="cat" itemValue="#{cat.nomCat}" itemLabel="#{cat.nomCat}" />
<p:ajax update="panl" event="change" listener="#{composantbean.catListener()}"/>
</p:selectOneMenu>
<p:panel id="panl" header ="Caracteristique selon la categorie" toggleable="true" rendered="true" >
<table>
<ui:repeat value="#{composantbean.categorie.proprietes}" var="var">
<tr>
<td><h:outputText value="#{var.nomProp}" /></td>
<td><h:inputText value="" /></td>
</tr>
</ui:repeat>
</table>
</p:panel>
i created a datatable which contains some test data. My problem is that some values are too large for one of my columns, that leads to a weird layout:
(after the order column two other columns should be displayed)
i already tried a few things out:
<p:column headerText="Orders" width="50"> no changes
<p:column headerText="Orders" style="max-width: 30px;"> makes the column smaler but the value is cut after 30px
adding after a few numbers a <br/> to force a breakline, but no changes
The order value is one big string. My goal is to change the orders column to a multiline column where the string value is splitted.
My datatable code:
<h:body>
<h:head>
</h:head>
<h:form id="form">
<p:dataTable id="customerTable" var="customer" value="#{customerDataTable.allCustomer}"
rows="25" paginator="true" emptyMessage="No customer found.">
<p:column headerText="Customer ID" style="text-align: center;">
<h:outputText value="#{customer.customerNumber}" />
</p:column>
<p:column headerText="Fist Name" style="text-align: center;">
<h:outputText value="#{customer.contactFirstName}" />
</p:column>
<p:column headerText="Last Name" style="text-align: center;">
<h:outputText value="#{customer.contactLastName}" />
</p:column>
<p:column headerText="Sales Employee Nr." style="text-align: center;">
<h:outputText value="#{customer.employee.employeeNumber}" />
</p:column>
<p:column headerText="Orders">
<h:outputText value="#{customer.allOrders}"/>
</p:column>
<p:column headerText="Payments" style="text-align: center;" >
<p:commandButton id="payment_btn" update=":form:p_display" oncomplete="paymentDialog.show()" icon="ui-icon-calculator">
<f:setPropertyActionListener target="#{customerDataTable.selectedCustomer}" value="#{customer}"/>
</p:commandButton>
<p:tooltip for="payment_btn" value="Click to see all payments" showEffect="fade" hideEffect="fade"></p:tooltip>
</p:column>
<p:column headerText="Contact Data" style="text-align: center;" >
<p:commandButton id="contact_btn" update=":form:c_display" oncomplete="contactDialog.show()" icon="ui-icon-home">
<f:setPropertyActionListener target="#{customerDataTable.selectedCustomer}" value="#{customer}"/>
</p:commandButton>
<p:tooltip for="contact_btn" value="Click to see the detailed contact data" showEffect="fade" hideEffect="fade"></p:tooltip>
</p:column>
</p:dataTable>
</h:form>
</h:body>
In other threads i found solutions using css but that didn't work either (the reason could be that i dont now how and where the css file and methods should be created).
If you want rows to break you can use CSS. Try adding this to your style
.ui-datatable td,.ui-datatable th {
white-space: normal;
}
This won't work if there are no blank spaces in your text, because the browser won't know where to break the line, in that case you could make use of the wbr tag, but it's important to say it's not supported by IE
See also:
http://www.w3schools.com/tags/tag_wbr.asp
try adding this to datatable scrollable="true" it worked.