PrimeFaces Datatable sticky header inside dialog - jsf

Stickyheader works in pages, I have a datatable inside a dialog which has more than 100 rows, user has to scroll down
<p:dialog>
<p:datatable stickyHeader="true" >
..
..
..
</p:datatable>
</p:dialog>
I need to enable fixed columnheaders for the datatable.

stickyHeader="true" won't work inside a dialog, finally i found an alternative solution to this
<p:dialog>
<p:datatable scrollable="true" scrollHeight="150" >
..
..
..
</p:datatable>
</p:dialog>
This worked well for me

Scrollable is something different than Sticky Header, but if you need your dataTable to behave exactly like primeface's Sticky Header, you can use this feature.
Here jsfiddle.net/DTcHh/1360/ is an easy example how to use it.

Related

How to create a dynamic p:menuButton inside a jsf dataTable?

I have a p:menuButton in a p:column in a p:dataTable.
So far everything works fine.
Now I want to make the menuButton dynamic. However c:foreach is evaluated before rendering the table and primefaces doesn't like to use ui:repeat inside the p:menuButton.
How can I create a number of p:menuitem dynamically based on a collection on the row item I am looping over, i.e. what should I do instead of ?:someKindOfLoop in the example below?
<p:dataTable value='#{something.collection}' var='item'>
...
<p:column>
...
<p:menuButton value="Actions">
<p:menuitem value="View ..."
...>
<f:param name="something" value="#{item.id}"/>
</p:menuitem>
<?:someKindOfLoop x="#{item.subCollection}" y="var">
<p:menuitem value="View sub list "
...>
<f:param name="#{var.name}" value="#{var.id}"/>
</p:menuitem>
</?:someKindOfLoop>
</p:menuButton>
...
</p:column>
</p:dataTable>
Googling yields a number of similar cases, however I haven't found one yet that wasn't either about dynamically creating columns (like this: Why can <c:forEach> or <ui:repeat> not access <p:dataTable var>? ) or that doesn't deal with primefaces.
The PrimeFaces p:menuButton, like many other components, including most menu components, supports the model attribute. This is mentioned on page 329 in the PF6 documentation. The 'Dynamic menus` section of this component refers to the 'common' dynamic menus section on page 323. There you can read how to do this.
And to prevent this answer to be a 'link only' (to external sites, here is the sort of duplicate of this question: Primefaces : how to create <p:menubar> dynamically in primefaces 4?

Primefaces : update dialog content and keep it open

I'm working with JSF and PrimeFaces, and I can't handle the following situation:
I have a dialog, and I placed a dataTable on it. In one of the cells of the table I would like to display given data in 3 different ways, and I'd like to switch between them. So far I managed to switch between these rendering types via commandLink, but my problem is that when I click on one of the 3 links, the dialog closes! Can I update the content of the dialog, and be able to keep it open the same time? (I'm updating which render type to use via myMethod)
my commandLink looks like this:
<p:commandLink id="id" update=":myForm:myDialog" ajax="false"
action="#{myBean.myMethod}" oncomplete="dialog.show()">
If i don't use the ajax=false attribute, the method is not called, and I also tried imediate=true, but that's not it either.
You need to define an p:outputPanel inside your dialog and update the outputpanel, not the dialog itself (that's why your dialog closes):
<p:dialog id="myDialog" ...>
<p:outputPanel id="myOutputPanel">
... your dialog content goes here
</p>
</p:dialog>
and change your commandlink
<p:commandLink id="id" update=":myForm:myDialog:myOutputPanel" ajax="true"
action="#{myBean.myMethod}" oncomplete="dialog.show()">
Regarding the oncomplete="dialog.show()" - I'm not entirely sure if you need that. A precise answer can be given if you provide more code regarding your table and code.
I had the same problem, and solution is to update a form instead of dialog. For example:
<p:dialog id="id_dialog" ...>
<h:form id="id_form">
... content
</h>
</p:dialog>
and commandLink:
<p:commandLink update=":id_form" process="#all" ...>
This worked for me!

Primefaces Paginator

I have a simple primefaces datatable with paginator="true". The table has data and the arrow buttons are showing for the paginator but when I click one nothing happens. It doesn't even appear to post back to the server. Here is my datatable declaration:
<p:dataTable id="datatable" var="currentRow" value="#{myBean.Items}" paginator="true" rows="10">
Am I missing something?
Thanks!
Make sure your table is inside a <h:form> element.

When pagination is activate in p:dataTable?

I am using primefaces 3.2
How can I know when the user is pushing one of the pagination button in p:dataTable ?
Thanks
If you need an ajax behaviour when user changes the page, you can use the following code:
<p:dataTable value="#{bean.collection}" var="obj" >
<p:ajax event="page" update="componentsToUpdateOnPage" listener="#{bean.pageListener}" />
<p:column>
.. etc..
</p:dataTable>
If you are using a lazy loading data table, you have to override the load() method of LazyDataModel. that method is executed on page load, when page changes and also when you sort or filter the datatable.

How to update a component inside of dataTable from outside of it

I am using Mojarra implementation of JSF 2.1 with Primefaces 3.2.
My problem approximately looks like this:
<p:dialog id="someDialog">
..
<h:form id="dialogForm">
<p:commandLink action=".."update=":someForm:someUIRepeat:someDataTable:someInputTextArea"/>
</h:form>
</p:dialog>
<h:form id="someForm">
<ui:repeat id="someUIRepeat" value=".." ..>
<p:dataTable id="someDataTable" value=.. >
<p:column>
<p:inputTextarea id="someInputTextarea" value=../>
<p:column>
.. here go other columns
<ui:repeat>
</h:form>
The issue is that when I click on the commandLink in the dialog the inputTextarea is not updated. However, if I write this in the update of the commandLink:
update=":someForm:someUIRepeat:someDataTable,:someForm:someUIRepeat:someDataTable:someInputTextArea"
then the whole dataTable gets updated and the inputTextarea updates as well, but the values in the fields located in other columns get erased after I click on the commandLink in the dialog.
The reason why I put dataTable inside of ui:repeat is that I need to bind a dataTable with each row of one collection and I think it's not related to my problem.
Any ideas how I can solve this problem?
Thanks in advance,
Nurzhan.
for start try this
added onclick="jQuery('#someForm:someButton').click();"(check the exact id of your hidden button) to your <p:commandLink inside the dialog
set the update to update=":someForm:someUIRepeat:someDataTable"
and add
<h:commandButton id="someButton" style="display:none">
<f:ajax execute="#form"></f:ajax>
</h:commandButton>
to <h:form id="someForm">
explanation: the purpose of the hidden button is to execute (send its values) the form to the server so that when you do call update the fields wont be erased...

Resources