How to display the values in open faces datatable? - jsf

Actually i am using open faces data table for selecting rows using the attribute < o:checkboxColumn rowDatas will automatically filter the currently selected rows .I didn't do any filter in Bean file,the selected list values are stored in my database table .My problem is how to display the selected list to other data table , if i did iteration only the values will be display (there is no need of iteration here ).
<o:dataTable id="type_parts_table"
value="#{employeeBean.srNameList}"
applyDefaultStyle="true" var="type_parts" width="600px"
pageSize="10" headerRowClass="header-table-row"
bodyRowClass="normal-table-row"
bodySectionClass="normal-table-row"
sortedColumnHeaderClass="sorted-header-row">
<o:column width="200px">
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{type_parts.name}" />
</o:column>
<o:column width="200px">
<f:facet name="header">
<h:outputText value="Type" />
</f:facet>
<h:outputText value="#{type_parts.head}" />
</o:column></o:dataTable>
Is there any attribute to display those values .

Related

How to filter date range with primefaces calendar?

I filter columns in data table with prime faces dataTable showcase example
<p:column id="logStatus" filterBy="#{log.status}" headerText="status">
<h:outputText value="#{log.status}" />
</p:column>
<p:column filterBy="#{log.mbr}" headerText="mbr">
<h:outputText value="#{log.mbr}" />
</p:column>
Everything works fine when the key is released filters are sent to my DAO where I do some logic.
I don't know how to implement this with <p:calendar>
I want to pick dates from calendar and sand it to DAO in the same way as it works with filters I provided above
A column with calendar, I need two calendars in one column
<p:column filterBy="#{log.datumOd}" headerText="datumupisa od">
<f:facet name="filter">
<p:calendar id="datumOd" pattern="dd/MM/yyyy">
<p:ajax event="dateSelect" />
</p:calendar>
</f:facet>
<f:facet name="filter">
<p:calendar id="datumDo" pattern="dd/MM/yyyy">
<p:ajax event="dateSelect" />
</p:calendar>
</f:facet>
<h:outputText value="#{log.datumUpisa}" />
</p:column>
I need explanation how filterBy works? Should i use update, on complete and event ? I tried to use two columns and filterby dateFrom and dateTo, but events not working. It works if i pick dates and then filter by other filters ( from above ).
I will proivde more info and code if needed.

<rich:extendedDataTable> <c:forEach> Displaying a table via a "Map of maps"

I have a data model with structure : TreeMap < String, TreeMap< String, Double>> resultMap;
This is stored in a SessionScoped ManagedBean.
I am trying to output this via a dynamic < rich:extendedDataTable> where;
Key of first map is the row label
Value of first map is a second map ( corresponds to the columns on the row
Key of second map is the columns header
Value of second map is the columns value
Source Code:
<rich:extendedDataTable
value="#{queryBean.resultMap.keySet().toArray()}" var="key"
frozenColumns="1" styleClass="rich-extdt">
<rich:column width="75px">
<f:facet name="header">
<h:outputText value="Mediation" />
</f:facet>
<h:outputText value="#{key}" />
</rich:column>
<rich:column width="75px">
<f:facet name="header">
<h:outputText value="Test" />
</f:facet>
<h:outputText value="#{queryBean.resultMap[key]}" />
</rich:column>
<c:forEach items="#{queryBean.resultMap[key]}" var="map">
<rich:column width="75px">
<f:facet name="header">
<h:outputText value="#{map.key}" />
</f:facet>
<h:outputText value="#{map.value}" />
</rich:column>
</c:forEach>
</rich:extendedDataTable>
Output:
The first column is correctly outputting the keys of the first map.
The second column (used for debugging) is correctly outputting the map structure ( when I apply .keySet() to the structure I do get all the correct keys ).
Using: jstl 1.2.0, jsf 2.1 - mojarra, richfaces 4.x, tomcat 7.
Update:
As stated here, the < c:forEach> has no access to the < rich:dataTable> attributes, hence unable to use key. Is there any simple workaround to this?

How can I make p:cellEditor conditional in PrimeFaces?

Here is my code that doesn't work:
...
<p:column sortBy="#{invoice.customerId}" id="customerId">
<f:facet name="header"><h:outputText value="Customer ID"/></f:facet>
<f:facet name="output" rendered="#{!editUIBean.isEditable('customerId')}">
<h:outputText value="#{invoice.customerId}"/>
</f:facet>
<p:cellEditor rendered="#{editUIBean.isEditable('customerId')}">
<f:facet name="output">
<h:outputText value="#{invoice.customerId}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{invoice.customerId}"/>
</f:facet>
</p:cellEditor>
</p:column>
...
So what I am trying to do: The user picks an option, that option determines which records are editable and only displays the records that are editable for that option. For any given option, only certain columns within those records are editable. The isEditable(columnName) method returns true if for given option the column is editable or false if it is not editable. What I want to do is, when the user clicks edit for the record, the editable fields display input fields and then non-editable fields display their values. With the code above, when the column isn't editable, the value doesn't display, before and after clicking edit. When the field is editable, the value displays, and when you click edit, the value is replaced with an input field containing the value. So my example works except that the value is completely hidden when the field is not editable. I want the non-editable values to be displayed when not editing and when editing, I just don't want them to be editable during edit.
This,
<p:column>
<f:facet name="output" rendered="#{!editUIBean.isEditable('customerId')}">
<h:outputText value="#{invoice.customerId}" />
</f:facet>
...
</p:column>
is not right. The <p:column> doesn't support a <f:facet name="output">. Just put the rendered condition on the <h:outputText> itself.
<p:column>
<h:outputText value="#{invoice.customerId}" rendered="#{!editUIBean.isEditable('customerId')}" />
...
</p:column>

convert screen into primefaces data table

I need to create a datatable in jsf using primefaces where i need to have one row in which one column contains static data with one button.When i will click on this button then the other columns(within the same row) should display some input text fields with label and data should be populated from database.It means if there are two records coming, then the column in that row should get spanned into the number of rows according to number of records.It means one column will be static and other column in that row should get dynamically spanned and some components should be added in the column within the row.please help me how to do this?
Hi somewhere down the line I found some sample code for dynamically creating rows, further u can nest it as required.
<p:column>
<f:facet name="header">
<h:outputLabel value="Field 2" />
</f:facet>
<h:outputLabel value="#{myTableVar.Field2}" />
</p:column>
<f:facet name="footer">
<p:commandButton value="New" action="#{myBean.prepareForInsert}" update=":myForm:myPanel"/>
</f:facet>
</p:dataTable>
<h:panelGrid id="myPanel" columns="2" >
<h:outputLabel value="Field 1"/>
<p:inputText id="fld1" value="#{myBean.newRec.field1}" />
<h:outputLabel value="Field 2"/>
<p:inputText id="fld2" value="#{myBean.newRec.field2}" />
<p:commandButton action="#{myBean.createAction}" value="Submit" update="myGrowl myTable" />
</h:panelGrid>
When New button is clicked, create an emty instance of newRec in prepareForInsert routine of myBean. So that myPanel is filled with blanks in the fields. On Submit, add the newRec to list_Recs and the new record is diplayed in the data table because of the update on myTable. Hope this helps.

Dynamically adding a row to primefaces dataTable

I need to add a row to my datatable on click of a button - "Add Employee".
The datatable shows the records corresponding to a fixed list of Employees in the bean.
What I am doing is, on click of the "Add Employee" button , I am adding an empty record of Employee to the empList.
Is there any better way to do this?
Thanks.
Either you open a dialog or a popup when clicking the add button. Then fill in the required fields (attached to a employee object. And when saving/submit you add that object to your list of employee objects. And rerender the datatable.
Or you can initially add an empty emploee object to your list. Showing it in the datatable with inputfields. On add, you add the new employee to the list and rerender the list.
list_Recs is list of records and shown in the data table.
<p:dataTable id="myTable" value="#{myBean.list_Recs}" selectionMode="single" var="myTableVar" selection="#{myBean.currentRec}">
<p:ajax event="rowSelect" listener="#{myBean.handleRowSelect}" update=":myForm:myPanel"/>
<p:column>
<f:facet name="header">
<h:outputLabel value="Field 1" />
</f:facet>
<h:outputLabel value="#{myTableVar.Field1}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel value="Field 2" />
</f:facet>
<h:outputLabel value="#{myTableVar.Field2}" />
</p:column>
<f:facet name="footer">
<p:commandButton value="New" action="#{myBean.prepareForInsert}" update=":myForm:myPanel"/>
</f:facet>
</p:dataTable>
<h:panelGrid id="myPanel" columns="2" >
<h:outputLabel value="Field 1"/>
<p:inputText id="fld1" value="#{myBean.newRec.field1}" />
<h:outputLabel value="Field 2"/>
<p:inputText id="fld2" value="#{myBean.newRec.field2}" />
<p:commandButton action="#{myBean.createAction}" value="Submit" update="myGrowl myTable" />
</h:panelGrid>
When New button is clicked, create an emty instance of newRec in prepareForInsert routine of myBean. So that myPanel is filled with blanks in the fields. On Submit, add the newRec to
list_Recs and the new record is diplayed in the data table because of the update on myTable.
Hope this helps.
A different option would be to show an empty employee in the footer facet of your datatable and add it to your list if the user clicks the add button. With this you can ensure that only correctly filled employee objects/entities are added to your list.

Resources