Create dropdown menu in h:dataTable for one specific row - jsf

I have a form that has a few fields that take input from the user. That input is then used to generate a dataTable that is being populated via Hibernate with info from the database, according to the options/fields selected by the user in the initial form.
I need to somehow generate a dropdown menu for a specific record that is being clicked on, and then download that record in a specific file format (I already kind of have a similar method for doing this made by someone else).
Here's how my dataTable looks like:
<h:form id="form2">
<t:dataTable binding="#{table}" rendered="#{searchArhivaUIBean.renderTable}" value="#{searchArhivaUIBean.nonEdiAbstractList}"
var="dataItem" border="0" cellspacing="2" width="100%" id="tdtbl"
headerClass="tableHeader" rowClasses="rowOdd,rowEven" columnClasses="Column">
<t:column>
<!-- display currently selected row number -->
<f:facet name="header">
<t:outputText value="Nr"/>
</f:facet>
<t:outputText value="#{table.rowIndex + 1}"/>
</t:column>
<t:column>
<f:facet name="header">
<t:outputText value="Data Mesaj"/>
</f:facet>
<t:outputText value="#{dataItem.dataMesaj}">
<f:convertDateTime timeZone="#{tzUIBean.tz}" pattern="dd.MM.yyyy" />
</t:outputText>
</t:column>
<t:column>
<f:facet name="header">
<t:outputText value="Numar Mesaj"/>
</f:facet>
<t:outputText value="#{dataItem.numarMesaj}"/>
</t:column>
<t:column>
<f:facet name="header">
<t:outputText value="Societate Sender"/>
</f:facet>
<t:outputText value="#{dataItem.societateSender}"/>
</t:column>
<t:column>
<f:facet name="header">
<t:outputText value="Societate Receiver"/>
</f:facet>
<t:outputText value="#{dataItem.societateReceiver}"/>
</t:column>
</t:dataTable>
</h:form>
This will generate a dataTable, populated with items. Any ideas on how can I make now a dropdown appear as I click a message (either the "Nr" column (the first column in the dataTable)) or the "Numar Mesaj" column? I need the dropdown to appear underneath that specific row in the dataTable, so I can choose the file format from that dropdown and download that specific record as a .pdf, .xls or whatever else type of file.
At least, this is how I thought it to work. Any ideas are appreciated.

Well, it would much easier to do with proper JSF framework like for instance Prime Faces. They have dedicated components for that kind of stuff.
With default JSF it will be a chunk of job. I can imagine something like that:
First you need to make one of your columns clickable with for instance h:commandLink. This (click) action may change special flag(s) which will be used to show an extra row with formats.
Next step is making extra rows for each data row where second row is hidden (by above flags). Clicking the link in your column will show that extra row with formats.
It seems the only difficulty is to show just 1 row, not all of them so the event and flags need to quite clever. You have to track the current row selection and use it when showing an extra row.

Related

use of cellEditor in facet not working primefaces

In a project, I have to merge two datatables (the first to set the header of the second and the second displaying the informations contained in an uploaded file) into one to simplify the legibility on the page.
Since the first datatable was using a cellEditor I tried using one in the merged one the following way for the header:
<f:facet name="header">
<p:cellEditor>
<f:facet name="output">
<h:outputLabel id="output" value="some text" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{handler.selectItems}">
<!-- List of selectItems -->
<p:ajax event="change" update="output" />
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</f:facet>
But when I build the project and click on the header of my columns, I don't have any list of selectItems appearing to give me the possibility to change the header. It was used in <p:column> before without problem so I imagine the <f:facet> is the problem
I succesfully made the possibility to change the value of the header using <p:inplace> instead, but it doesn't behave exactly like I want.
I want that even if I don't modify the value when I click on the header (and make the list appears), I can click somewhere on the page and make the list disappear to have a "clean" header. I don't really want to use the editor="true" option of inplace because the goal is also to try to reduce the number of click needed for the user. I also made it a bit using <p:ajax event="blur" update="output" /> but some value of the list of selectItems make one or two inputText appear. And with that event, when I click in the text box, it closes the field automatically and I can only the value of the field once. After, the moment I click on the list to open it, it closes the field.
How can I fix that ?

p:pickList ignores attributes of <p:column>

I am currently developing an application where the user can use a picklist to make certain associations.
I would like to display the object's attributes in different columns inside the picklist, for example the object car would display its id, year and color. However, the headerText of the column is not working. The column only displays the data but PrimeFaces seems to ignore the attribute headerText among others like sortBy. Is there any workaround? What am I doing wrong? p:column seems to work fine on a DataTable but not on a PickList and I really need to use a PickList or at least something with very similar functionalities.
Below is my code:
<p:pickList id="pickListAssociacao" value="#{associacaoPickListView.carsPickListView}" var="car" itemLabel="#{car.brand}" itemValue="#{car}">
<p:column headerText="Header1">
<h:outputText value="#{car.brand}" />
</p:column>
<p:column headerText="Header2" sortBy="#{car.year}">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Header3">
<h:outputText value="#{car.year}" />
</p:column>
</p:pickList>
Thanks for your time.

p:rowExpansion gets rendered even though it's not toggled

I have a problem with data in a <p:rowExpansion> being loaded before the row is expanded (which leads to loads of web service requests).
I am using PrimeFaces 5.2. I have a dataTable with lazy loading and pagination. Inside of the table, I have <p:rowToggler> with a <p:rowExpansion>:
<p:dataTable var="order"
widgetVar="orderTable"
lazy="true"
value="#{ordersBean.orders}"
paginator="true"
rows="20"
rowsPerPageTemplate="20,50,100"
filterDelay="300"
styleClass="filtered">
<p:column width="4%">
<p:rowToggler />
</p:column>
<p:column headerText="Order number" width="96%">
<h:outputText value="#{order.number}" />
</p:column>
<p:rowExpansion>
<h:panelGrid columns="1">
<h:outputText value="#{order.number}" />
<h:outputText value="#{order.info}" />
<h:dataTable var="item" value="#{ordersBean.getItemsInOrder(order.number)}">
<h:column>
<h:outputText value=" #{item.title}" />
</h:column>
</h:dataTable>
</h:panelGrid>
</p:rowExpansion>
</p:dataTable>
When I first load the page, the getItemsInOrder() method is not called, except for when I expand a row. But if I navigate to page 2 (or if I navigate back to page 1 later) using the paginator, then getItemsInOrder() is called for every row in the outer table. Since I have 20 rows showing, navigating between the pages leads to 20 web service requests (in getItemsInOrder()).
How do I prevent it from calling the getItemsInOrder() method until the row is expanded?
I have the same problem. Until I find a better solution, this is the workaround I am using:
register a (DataTable event-) listener on event rowToggle.
In the listener, store an identifier of the toggled row. Hint: you can get the row object with event.getData()
Instead of directly accessing the data requesting component, write a proxy method in front of it which checks if the requested object belongs to the identifier stored in the listener.

JSF 2 h:dataTable with inputText values binded to List. Values not updating [duplicate]

This question already has an answer here:
Using <ui:repeat><h:inputText> on a List<String> doesn't update model values
(1 answer)
Closed 7 years ago.
I'm trying to display the data from a List contained in a bean via a datatable, and have actions performed by code as the user types. It initially displays ok, and changes to the List are reflected in UI.
My issue is that values entered into the inputText are ignored. Tried looking for solutions, I've tried checking the List as the values changed, and also tried to check without the ajax in case that was the issue (no change). Have tried using session and view scoped bean without luck. Tried wrapping the Strings in a POJO.
Going crazy here. Feel like I'm missing something obvious. Any idea?
<h:dataTable id="multioptionanswers"
value="#{multiTextBean.texts}" var="texts">
<h:column>
<f:facet name="header">
<h:outputText value="Enter Values"></h:outputText>
</f:facet>
<h:inputText value="#{texts}" immediate="true">
<f:ajax event="blur" execute=":addgroup"
render=":addgroup"
listener="#{multiTextBean.update}" />
</h:inputText>
</h:column>
</h:dataTable>
**addgroup is a panel group that the data table resides in.
Worked it out, needed change to how the inputtext read the data. Solution below in case it helps someone :
<h:dataTable id="multioptionanswers" binding="#{table}"
value="#{multiTextBean.texts}" var="texts">
<h:column>
<f:facet name="header">
<h:outputText value="Enter Values"></h:outputText>
</f:facet>
<h:inputText
value="#{multiTextBean.texts[table.rowIndex]}">
<f:ajax event="blur" execute=":addgroup" render=":addgroup"
listener="#{multiTextBean.update}" />
</h:inputText>
</h:column>
</h:dataTable>

OpenFaces Composite Filter does not render the user search input text field

Good Afternoon,
I am trying to use the composite filter but in vain. While we struggled the whole day trying to know that it does not work if the table contains a column with action buttons and no data type, now we are wondering why it does not render the text field for the user to type his filter criteria.
We click on the (+) button = A drop
down with column names is rendered.
2- From this dropdown, we choose a
column.
3- A 'NOT' checkbox and Another
dropdown with expressions (equals,
contains...etc) is rendered.
4- We choose an expression from the
list.
5- The input text field supposed to be rendered is not rendered at all.
Which makes the composite filter non usable as the user cannot type his search criteria!
Please help.
<div>
<h:form>
<o:compositeFilter id="bookfilter" for="bookstable" autoDetect="true"/>
<o:dataTable id="bookstable" sortColumnId="title" value="#{bookController.items}" var="item" >
<o:singleRowSelection />
<f:facet name="header">
Book TABLE
</f:facet>
<f:facet name="columnMenu">
<o:columnMenu/>
</f:facet>
<o:column id="title" sortingExpression="#{item.title}" header="title">
<h:outputText value="#{item.title}"/>
</o:column>
<o:column id="topic" header="topic">
<h:outputText value="#{item.topic}"/>
</o:column>
<o:column id="writer" header="writerid" >
<h:outputText value="#{item.writer}"/>
</o:column>
</o:dataTable>
Appearently It is a bug affecting versions of Mojarra ulterior to 2.0.3 (2.0.4+).
http://requests.openfaces.org/browse/OF-81
And not fixed yet in the nightly builds.

Resources