Primefaces <p:dataExporter> does not produce Excel download - excel

I'm having a problem with the PrimeFaces component p:dataExporter. Here is my code:
<p:commandButton value="Export to Excel" ajax="false">
<p:dataExporter type="xls" target=":mainForm:mainTable" fileName="export" />
</p:commandButton>
When I click on the button it just refreshes the XHTML page and produces no XLS downloads. I have tried both h:commandButton and h:commandLink but it still doesn't work. Also, I have tried linking POI v3.10 and v3.7 but still the same error. I have no idea how to proceed. Please help.

I'll say my problem that I had with this, I hope this helps:
My problem was that, when the page was reloaded my dataTable was reloaded every time and when I change my data by filter o sort something, the values was newly reloaded and when the user filter by something the dataTable change, but when him click to export, the page newly charge and the values charge again, and the export doesn't had the correct values. I've changed the scope of my ManagedBean from: #ViewScoped to #SessionScoped, of that way when the page is reloaded the values of the query is permanent and when I filter by something and refresh the page, the same values are permanent therefore when i click to export, the correct values are exported.

Related

Bean value is getting set on click of a cancel button in JSF, How to avoid this? [duplicate]

I have a JSF/PrimeFaces form page set up to edit some configuration details. At the bottom are Submit and Cancel buttons implemented as CommandButton. The Cancel button looks like this:
<p:commandButton
action="priorPage.xhtml?faces-redirect=true"
value="Cancel" />
The problem is that the view bean still winds up doing more processing on the data that's been entered into the form than I'd like. It isn't updating anything in the database, but if (say) I enter a string into a field that's looking for a numeric in the bean, it still produces errors.
Part of my solution is, of course, to get the bean to gracefully handle that sort of bad data, and I'm working on it. But I'd also like to tweak that button so that it just takes the user to the prior page. Is there some attribute I can set that will prevent the form from being processed at all?
The <p:commandButton> submits the form. You don't want to submit the form. You should then not use the <p:commandButton>, but just <p:button>.
<p:button value="Cancel" outcome="priorPage.xhtml" />
See also:
Difference between h:button and h:commandButton

h:selectBooleanCheckbox stays checked after page reloads

I have come across some small but annoying problem when developing an application using JSF 2.2.
On my .xhtml page I have h:dataTable and one of it's columns consists of h:selectBooleanChecbox objects. It doesn't really matter what this checkbox do, but my problem is that when I check one or more checkboxes and then reload the page in the browser, the checkboxes I've previosly ticked stays checked, what is of course not what I expect to happen.
My h:selectBooleanCheckbox is like following:
<h:selectBooleanCheckbox disabled="${firstLaunchBackingBean.disableFirstPhaseForm}" onselect="#{firstLaunchBackingBean.addSelectedEmail(item)}">
<f:ajax render="#this" execute="#this"/>
</h:selectBooleanCheckbox>
I also have to mention that my backing bean is conversation scoped, but I don't know if it has anything to do with my problem.

Update JSF in carusell

I currently try to implement a website, where an dialog, opened from an carousel, changes something in the database and the result is shown on the screen. For that, I try to update an area in the dialog. Unfortunately, updating things in an carusell does not seem to work.
I shortened the code to an minimal example, so with the following code:
<p:carousel id="page" value="#{pagebean.pages}"
var="item" numVisible="1">
<h:form id="dlg_2_form">
<h:outputText id="test_2" value="#{pagebean.value}" />
<p:remoteCommand name="update_2" update="test_2" />
Increment
</h:form>
</p:carousel>
the function pagebean.value is not called after I click on Increment, but therefore the constructor of pagebean is called when I click on Increment. So it seems like the carousel makes it impossible to update something in it.
Does anyone know, if there is an possibility to update something which is in a carousel, or if there is a workaround for this problem?
EDIT: After the discussion below, I know that Increment does work, if the scope of the corresponding bean is set to #ViewScoped. I could also trigger this button by giving it a widgetVar and accessing its click function, so this would work. Unfortunately, the Bean I want to use is SessionScoped, and with this kind of view it does not work. Has anybody an hint how to solve this problem? I could copy everything into a second Bean, which is ViewScoped, but this is not a very nice solution.

PrimeFaces CommandButton that Doesn't Process Data

I have a JSF/PrimeFaces form page set up to edit some configuration details. At the bottom are Submit and Cancel buttons implemented as CommandButton. The Cancel button looks like this:
<p:commandButton
action="priorPage.xhtml?faces-redirect=true"
value="Cancel" />
The problem is that the view bean still winds up doing more processing on the data that's been entered into the form than I'd like. It isn't updating anything in the database, but if (say) I enter a string into a field that's looking for a numeric in the bean, it still produces errors.
Part of my solution is, of course, to get the bean to gracefully handle that sort of bad data, and I'm working on it. But I'd also like to tweak that button so that it just takes the user to the prior page. Is there some attribute I can set that will prevent the form from being processed at all?
The <p:commandButton> submits the form. You don't want to submit the form. You should then not use the <p:commandButton>, but just <p:button>.
<p:button value="Cancel" outcome="priorPage.xhtml" />
See also:
Difference between h:button and h:commandButton

Input fields not clearing after the validation fails

I have a form, it contains username and password etc... if i gave any wrong value the validation will fail. next if i see the form na that previously given values are coming in the input fields.. i cleared the bean values also. but the input fields are not yet cleared.
i have cleared the input fields using the following link 1st step.
https://cwiki.apache.org/MYFACES/clear-input-components.html
this is working but what the problem is this is working only in <rich:datatable> 1st page.
if i have navigate to second page and next pages and all that Popup panel itself not opening.
i am using the jsf version 2.0,
Please provide a good solution.
Thanks,
You can add OmniFaces Library to your project and use their ResetInputAjaxActionListener
Like this
<h:commandButton value="Update" action="#{bean.update}">
<f:ajax execute="#this" render="#form" />
<f:actionListener type="org.omnifaces.eventlistener.ResetInputAjaxActionListener" />
</h:commandButton>
Read more about it on BalusC blog Reset non-processed input components on ajax update
Are you using session scope ? Change it to request scope. Otherwise, add your xhtml page and bean class.

Resources