Problem exporting dataTable

UI Components for JSF
rohopo
Posts: 6
Joined: 12 Sep 2016, 15:44

12 Sep 2016, 16:10

I have a p:dataTable that renders fine on the screen, but when I export it to excel (or other formats), only the header row shows up. To debug this, I have reduced the dataTable down to the following:

Code: Select all

<p:dataTable id="requirements"
			 value="#{simsReqListController.requirements}" 
			 var="req" style="vertical-align: top; border:1pt solid black;"
			 cellpadding="2" cellspacing="0">
	<p:column>
		<f:facet name="header">
			<h:outputText escape="false" value="#" />
		</f:facet>
		<h:outputText value="#{req.recordCount}" />
	</p:column>
</p:dataTable>
I export it using the following code:

Code: Select all

<h:commandButton value="Export to Excel">
	<p:dataExporter type="xls" target="requirements" fileName="Requirements List"/>
</h:commandButton>
My environment: Primefaces 6.0, Poi 3.9, JSF 2.2, JBoss EAP 6.4.7

Please let me know what other information I can provide to help clarify my situation. Thanks!

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4345
Joined: 16 Oct 2011, 19:19
Location: Singapore

12 Sep 2016, 20:09

The code looks good and export should work perfectly.What is the scope of your managed bean?
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

rohopo
Posts: 6
Joined: 12 Sep 2016, 15:44

12 Sep 2016, 21:16

The managed bean is currently set to session scope. It was view, but I changed it to session hoping that would solve the problem

smokeybandit
Posts: 277
Joined: 08 Jul 2013, 17:53

13 Sep 2016, 13:13

Is the "requirements" property possibly getting wiped out from the time it's rendered on the screen to when you try to export it?

rohopo
Posts: 6
Joined: 12 Sep 2016, 15:44

13 Sep 2016, 15:09

That is entirely possible. I physically placed the export commandButton after the dataTable in the xhtml file thinking that might help. I will try to debug further and make sure the "requirements" property is still valid at export time. Not quite sure how to do that yet, any suggestions would be greatly appreciated.

smokeybandit
Posts: 277
Joined: 08 Jul 2013, 17:53

13 Sep 2016, 15:31

Try setting your data table value to some hard coded test value. If the exporter works as expected then, you have your clue.

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4345
Joined: 16 Oct 2011, 19:19
Location: Singapore

13 Sep 2016, 16:35

Or try to provide simple maven project with simple xhtml and managed bean.
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

rohopo
Posts: 6
Joined: 12 Sep 2016, 15:44

14 Sep 2016, 17:31

@smokeybandit: I gave that a try. I changed the bean reference in the xhtml to a constant ("5"). On the screen I get many rows of "5"s, but still only the header row shows up when I do an export.

@sudheer: Unfortunately, we don't use Maven on this project so I can't easily go down that path.

My next attempt will be to create a new "bare bones" xhtml and get that to work. Once I do that, I will connect it to a simple backing bean and get that to work. I'm basically trying to determine if it's my code or my configuration.

Thanks to both of you for your feedback, and any further guidance would be awesome.

smokeybandit
Posts: 277
Joined: 08 Jul 2013, 17:53

14 Sep 2016, 18:12

Possibly a dumb question, but is the dataExporter tag embedded in an h:form?

rohopo
Posts: 6
Joined: 12 Sep 2016, 15:44

14 Sep 2016, 18:54

Definitely not a dumb question, better to be safe. Yes, both the dataTable and the dataExporter are embedded in the same h:form.

Based on my latest test, I think my configuration is fine and my xhtml is fine. I think the problem is in my backing bean.

I changed my dataTable code to read as follows:

Code: Select all

<p:dataTable id="requirements"
			 value="#{simsReqListController.reqtest}" 
			 var="req">
	<p:column>
		<f:facet name="header">
			<h:outputText escape="false" value="#" />
		</f:facet>
		<h:outputText value="#{req.intValue()}" />
	</p:column>
</p:dataTable>
I then added the following to my backing bean:

Code: Select all

reqtest = new ArrayList<>();
reqtest.add(1);
reqtest.add(2);
reqtest.add(3);
This displays 3 rows, 1 2 and 3. The export to excel also show the same thing. So, I really think my backing bean is losing the value of the "requirements" property as you mentioned earlier. I will continue down that path. Thank you.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 51 guests