Export JasperReports to XSL (Excel) or DOC (Word) - jsf

I have a situation. I want to generate a report and open it in another window in the JSF platform using JasperReports framework. Right now, I am able to generate the PDF version of the report. The following is the JSF view for the report:
<h:panelGrid columns="2">
<h:outputText value="#{lang.member}: *" />
<h:selectOneMenu converter="memberConverter" value="#{memberProcesListBean.member}" required="true" requiredMessage="#{lang.memberGroupIntroduction_memberGroupName_req_txt}">
<f:selectItem itemLabel="#{lang.select}..."/>
<f:selectItems value="#{memberProcesListBean.memberMenu}"/>
</h:selectOneMenu>
<h:outputText value="#{lang.startDate}: *" />
<p:calendar pattern="dd.MM.yyyy" required="true" requiredMessage="#{lang.defaultProcesses_defaultDate_req_txt}" value="#{memberProcesListBean.startDate}"/>
<h:outputText value="#{lang.endDate}: *" />
<p:calendar pattern="dd.MM.yyyy" required="true" requiredMessage="#{lang.defaultProcesses_defaultDate_req_txt}" value="#{memberProcesListBean.endDate}"/>
<h:outputText value="#{lang.metalCode}: *" />
<h:selectOneMenu converter="metalCodeConverter" value="#{memberProcesListBean.metalCode}" required="true" requiredMessage="#{lang.memberGroupIntroduction_memberGroupName_req_txt}">
<f:selectItem itemLabel="#{lang.select}..."/>
<f:selectItems value="#{memberProcesListBean.metalCodeMenu}"/>
</h:selectOneMenu>
<h:outputText value="#{lang.reportFormat}: *" />
<h:selectOneMenu id="ReportFormat" value="#{memberProcesListBean.fileFormat}">
<f:selectItems value="#{generalInfoBean.fileFormatsList}" />
</h:selectOneMenu>
</h:panelGrid>
<br/>
<br/>
<h:commandLink value="Download" action="#{uyeIslemListesiBean.retrieveReport}" target="_blank" />
However, I weren't able to retrieve and open in another window in the Excel and Word formats of the report. Should I change something in the view segment?
Yours sincerely...

I shouldn't say this, but there is a plugin that may help you to achieve that: JasperReports JSF Plugin. Take a look to its documentation and check if it fits your needs. But I would do, basically, is replace your for a . Since the report is generated in a secondary request you can still bind it to the values of your backing bean, maybe, by means of a custom report source.

Related

Efficiency of ajax update using #form vs #parent vs specific ids vs p:autoUpdate

PrimeFaces Showcase includes this (slightly amended) code as a demonstration in the use of p:focus.
<h:form id="form">
<p:focus id="focus" context="panel"/>
<p:messages id="messages"/>
<h:panelGrid id="panel" columns="3" cellpadding="7">
<p:outputLabel for="username" value="Username"/>
<p:inputText id="username" value="#{focusView.username}" required="true" />
<p:message for="username"/>
<p:outputLabel for="email" value="Email"/>
<p:inputText id="email" value="#{focusView.email}" required="true" />
<p:message for="email"/>
</h:panelGrid>
<p:commandButton value="Save" action="#{focusView.save}"
update="#parent" />
</h:form>
The update="#parent" clause could have been written in several ways and have the same effect.
update="#form"
update="#parent"
update="focus messages panel"
update="focus messages username username:#next email email:#next"
using p:autoUpdate on p:focus, p:messages and p:panelgrid (no update=)
using p:autoUpdate on p:focus, p:messages, username and its message and on email and its message
(Plus others.) I could argue that option 1 is the best and least error prone from a programmer's and support perspective. However which is most efficient and why? Are there any other factors that should be considered in choosing an option?

richfaces 4 extendeddatatable not showing updated data after ajax render

Environment:
Jboss 7.1.1.Final JSF 2.2.6 Seam 2.3.1.Final Richfaces 4.5.10.Final
Issue
Richfaces 4 extendeddatatable on render does not hold the value (Resource dropdown in the example listed below).
Steps:
First I choose a value from the Resource dropdown
Then I choose a value form the Result dropdown which triggers the a4j:ajax call
My XHTML structure is as listed below:
<a4j:region id="hraregion">
<rich:extendedDataTable id="hraProcessing"
value="#{maActionList}" var="mpa" selectionMode="single">
<h:column width="200px">
<f:facet name="header">
<h:outputText value="Resource" />
</f:facet>
<h:selectOneMenu id="staffResources" value="{mpa.staffResources}" label="Resource"
<s:selectItems value="#{mpa.validStaffResources}" var="sr" label="#{sr.firstName} #{sr.lastName}"/>
<s:convertEntity />
</h:selectOneMenu>
</h:column>
<rich:column width="140px">
<f:facet name="header">
<h:outputText value="Result" />
</f:facet>
<h:selectOneMenu id="results" value="#{mpa.actionResults}">
<a4j:ajax execute="region" listener="#{maintainAssessment.performNextAction(mpa, 'mpa')}" render="hraProcessing, actionMessage" />
<s:selectItems value="#{mpa.validActionResults}" var="ar" label="#{ar.name}" noSelectionLabel="Select One" />
<s:convertEntity />
</h:selectOneMenu>
</rich:column>
</rich:extendedDataTable>
</a4j:region>
Note:
We are migrating from Richfaces 3.3 to 4.5 and this functionality was working fine in Richfaces 3.3 but ofcourse the entire page was refreshed in 3.3 as opposed to the partial refresh in Richfaces 4.5
Can someone please point me in the right direction on how to retain the selected value after the a4j render happens?
I found a way to accomplish this by updating the backing bean immediately using f:ajax after the value changes in the Resource dropdown. Hope this helps someone who faces the same issue.
<h:selectOneMenu id="staffResources" value="#{mpa.staffResources}"
label="Resource" styleClass="LFloat">
<s:selectItems value="#{mpa.validStaffResources}" var="sr"
label="#{sr.firstName} #{sr.lastName}"/>
<s:convertEntity />
<f:ajax event="valueChange" execute="#this" render="#none"/>
</h:selectOneMenu>

Update components without processing in Primefaces

I would like to update a component without processing it. I use a binding get the value of a checkbox and decide if the other component should be rendered. Unfortunately, the update? or the binding? doesn't work as i would.
<p:selectBooleanCheckbox id="isPercentage" value="#{myBean.isDiscountInPercentage}"
label="Percentage" binding="#{discountInPercentage}">
<p:ajax process="" update="outpDiscountValue" />
</p:selectBooleanCheckbox>
<p:outputPanel id="outpDiscountValue">
<h:outputLabel value="$" rendered="#{!discountInPercentage.value}" />
<h:outputLabel value="%" rendered="#{discountInPercentage.value}" />
</p:outputPanel>

Primefaces SelectOneMenu not rendering properly with text

I am trying a userform with primefaces 3.5, all the components are working fine except selectonemenu, which not render correctly.
Its text field is not showing on selection of any drop down field.
i can't post image as i don't have that much reputation
Code
<p:panelGrid id="jobsGrid" columns="2" style="width:100%;margin-bottom:20px;margin-top:20px; margin-left:20px;margin-right:20px;text-align:left;">
<f:facet name="header"> ----- Quick Job Posting -----</f:facet>
<h:outputText value="OLF Number " />
<p:inputText value="#{jobs.jobDetail.OLF_No}" />
<h:outputText value="RRF Number " />
<p:inputText value="#{jobs.jobDetail.RRF_No}" />
<h:outputText value="OLF Status " />
<p:selectOneMenu value="#{jobs.jobDetail.OLF_Status}" style="margin-top:0px;margin-bottom:0px;height:5px;font-size:10px">
<f:selectItem itemLabel="---- Select ----" itemValue="" />
<f:selectItem itemLabel="Approved" itemValue="Approved" />
<f:selectItem itemLabel="Pending Approval" itemValue="Pending Approval" />
<f:selectItem itemLabel="New" itemValue="New" />
</p:selectOneMenu>
<h:outputText value="RRF Type " />
<p:selectOneMenu value="#{jobs.jobDetail.RRF_type}" style="margin-top:0px;margin-bottom:0px;height:5px;font-size:10px">
<f:selectItem itemLabel="---- Select ----" itemValue="" />
<f:selectItem itemLabel="Growth" itemValue="Growth" />
<f:selectItem itemLabel="Replacement" itemValue="Replacement" />
</p:selectOneMenu>
Screen Shot
How can i fix this ?
I fixed this this problem by adding following CSS to my page:
.ui-selectonemenu label.ui-selectonemenu-label{
width:100% !important;
}
I also have fixed widths on my selectonemenus.
Hope this helps in your case also. ;)
This is definitely a problem in Primefaces 3.5. I had the exact same issue, and downgrading to 3.4 solved it.
As a data point, it is worth noting that the rendering problem only existed when I navigated to the page through a p:remoteCommand. Normal action-based navigation works correctly, at least for me.
You can post your code some here, or if not try checking BalusC http://balusc.blogspot.nl/2007/09/objects-in-hselectonemenu.html
If you see that your bean annotations are correct, try using primefaces 3.4 or lower versions.

Ajax is not always working

below you see some part of my code, i just want to select the first value in a form and the rest should be updated via ajax, for example if you select PK than, MccName, MccVorname,MccDepartment should be shown via ajax after this selection.
This should also be possible in other forms indepently,
<h:panelGrid columns="4">
<h:form id="formmcc10">
<h:outputText value="Pls select PK: " />
<p:selectOneMenu value="#categorymcc.mcccatname}" id="mcccat"
immediate="true" valueChangeListener="#categorymcc.processScat}">
<f:selectItem itemLabel="#categorymcc.mcccatname}"itemValue="" />
<f:selectItems value="#categorymcc.categoryName}" />
<p:ajax update="formmcc10:mccscat1 formmcc10:mccscat2 formmcc10:mccscat3" event="change" />
</p:selectOneMenu><h:outputText value="Mcc Name" />
<p:selectOneMenu value="#{categorymcc.submcccatname}"id="mccscat1">
<f:selectItemsvalue="#{categorymcc.subCategoryName}" />
</p:selectOneMenu>
<h:outputText value="Mcc Vorname" />
<p:selectOneMenu value="#{categorymcc.subsubmcccatname}"id="mccscat2">
<f:selectItems value="#{categorymcc.subSubCategoryName}" />
</p:selectOneMenu>
<h:outputText value="Mcc Department:" />
<p:selectOneMenu value="#{categorymcc.abteilung}" id="mccscat3">
<f:selectItems value="#{categorymcc.abteilungCategoryName}" />
</p:selectOneMenu>
</h:form>
</h:panelGrid>
This could be anything, but I encountered one interesting problem like that recently. I tried to output a bean property like #{myBean.otherBean.name} and it worked when I loaded the page by normal request, but it didn't work with AJAX. When I tried #{myBean.otherBean.id}, it worked in both cases.
The problem was, that backend system didn't fill all data for otherBean on AJAX request, it filled only id (probably for better performance). I had to prepare a getOtherBeanById method and when I called that, AJAX started to work as expected.
I'm not an expert on this field, perhaps someone has a more precise explanation for that.

Resources