I tried to export the data from my datatable but when I press the pdf button for example it refresh the page without export
<h:commandLink >
<p:graphicImage value="/images/excel.png" />
<p:dataExporter type="xls" target="dataTable" fileName="alarms" />
</h:commandLink>
<h:commandLink >
<p:graphicImage value="/images/pdf.png" />
<p:dataExporter type="pdf" target="dataTable" fileName="alarms"/>
</h:commandLink>
<h:commandLink >
<p:graphicImage value="/images/csv.png" />
<p:dataExporter type="csv" target="dataTable" fileName="alarms" />
</h:commandLink>
<p:commandLink> has to be surrounded by <h:form> tag to work.
If this is not the problem can you please provide the source code of your whole page and the PrimeFaces version you are working with?
<h:commandLink style=" text-align: right!important;"
immediate="true" id="excelLinkId" ajax="false" >
<p:dataExporter type="xls" target="myTable" fileName="myExcel" />
</h:commandLink>
Related
I found these animations for jsf components : http://www.animatejsf.org/
I tried applying this to a <h:form> from a commandlink click as shown
<h:form id="leftMenu">
Slide
</h:form>
<p:commandLink>
<p:outputLabel> click here
<aj:animate target="leftMenu" type="slideInLeft"/>
</p:outputLabel>
</p:commandLink>
But the animation is not visible on click of the command link. Instead it is animating on web page loading initially only. I wanted to apply this animation on click of either a <p:commandButton> or <p:commandLink>.
Does anyone know how can I achieve this? Any help is appreciated.
Have you already tried:
<p:effect type="clip" event="click" />
Here an example:
<h3 style="margin-top:0">Catalog</h3>
<h:panelGrid columns="4" cellpadding="5">
<p:panel id="blind" header="Blind">
<h:outputText value="click" />
<p:effect type="blind" event="click">
<f:param name="direction" value="'horizontal'" />
</p:effect>
</p:panel>
<p:panel id="clip" header="Clip">
<h:outputText value="click" />
<p:effect type="clip" event="click" />
</p:panel>
<p:panel id="drop" header="Drop">
<h:outputText value="click" />
<p:effect type="drop" event="click" />
</p:panel>
<p:panel id="explode" header="Explode">
<h:outputText value="click" />
<p:effect type="explode" event="click" />
</p:panel>
<p:panel id="fold" header="Fold">
<h:outputText value="doubleclick" />
<p:effect type="fold" event="dblclick" />
</p:panel>
<p:panel id="puff" header="Puff">
<h:outputText value="doubleclick" />
<p:effect type="puff" event="dblclick" />
</p:panel>
<p:panel id="slide" header="Slide">
<h:outputText value="doubleclick" />
<p:effect type="slide" event="dblclick" />
</p:panel>
<p:panel id="scale" header="Scale">
<h:outputText value="doubleclick" />
<p:effect type="scale" event="dblclick">
<f:param name="percent" value="90" />
</p:effect>
</p:panel>
<p:panel id="bounce" header="Bounce">
<h:outputText value="click" />
<p:effect type="bounce" event="click" />
</p:panel>
<p:panel id="pulsate" header="Pulsate">
<h:outputText value="click" />
<p:effect type="pulsate" event="click" />
</p:panel>
<p:panel id="shake" header="Shake">
<h:outputText value="click" />
<p:effect type="shake" event="click" />
</p:panel>
<p:panel id="size" header="Size">
<h:outputText value="click" />
<p:effect type="size" event="click">
<f:param name="to" value="{width: 200,height: 60}" />
</p:effect>
</p:panel>
</h:panelGrid>
<h3>Target</h3>
<p:commandButton type="button" value="Show" style="display:block" icon="ui-icon-image">
<p:effect type="puff" event="click" for="img">
<f:param name="mode" value="'show'" />
</p:effect>
</p:commandButton>
<p:graphicImage id="img" name="demo/images/nature/nature1.jpg" style="display:none"/>
<h:form>
<h3>On Load</h3>
<p:messages id="messages" closable="true">
<p:effect type="pulsate" event="load" delay="500" />
</p:messages>
<p:panel id="panel" header="Message Effects" toggleable="true">
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="text" value="Type:" />
<p:inputText id="text" value="#{effectView.text}" required="true" />
<h:outputText />
<p:commandButton id="submit" value="Echo" actionListener="#{effectView.echo}" update="messages"/>
</h:panelGrid>
</p:panel>
</h:form
>
package org.primefaces.showcase.view.misc;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
#ManagedBean
public class EffectView {
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public void echo() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("You said:'" + text + "'"));
}
}
http://www.primefaces.org/showcase/ui/misc/effect.xhtml
That's worked fine for me with a commandLink.
I want to use dataExporter as onclick action in my right-click contextMenu.
Sadly, I have no idea how to manage this :(
dataExporter(simple export table date to XLS) and contextMenu are binded to the same dataTable.
here's the code:
<p:contextMenu for = "tableForm">
<p:menuitem value="View" icon="ui-icon-search"/>
<p:menuitem value="Delete" icon="ui-icon-close" />
</p:contextMenu>
<p:commandLink ajax="false" width="24">
<p:graphicImage value="/resources/images/Excel-icon.png" />
<p:dataExporter type="xls" target="dataTable"
fileName="daneCentrumDataTable" />
</p:commandLink>
Anyone knows how to do this?
Following #Kukeltje idea something like this:
<p:contextMenu for="dataTable">
<p:menuitem value="View" icon="ui-icon-search"/>
<p:menuitem value="Delete" icon="ui-icon-close" />
<p:menuitem value="Export" onclick="$('#export').click()" />
</p:contextMenu>
<div style="display: none;">
<p:commandLink id="export" ajax="false" width="24">
<p:dataExporter type="xls" target="dataTable" fileName="daneCentrumDataTable" />
</p:commandLink>
</div>
P.S.: My h:form has prependId="false"
i have one form inside the form i have one datatable and one chart so i need to export both in either PDF or excel file, i am using following command for export data
<h:form id="contenForm">
<!-- chart -->
<p:chart type="bar" model="#{dataModel.barModel}" id="barChart" />
<!-- Datatable -->
<p:dataTable value="#{dataModel.list}" var="loc" width="100%" paginator="true"
id="tableResulta" paginatorPosition="bottom" tableStyle="margin:0 auto; width:100%" rendered="#{not empty dataModel.list}">
<p:column>
<f:facet name="header">
<h:outputText value="Surname" />
</f:facet>
<h:outputText value="#{loc.surname}" />
</p:column>
<!-- and other colume-->
</p:dataTable>
<!-- Export button -->
<h:panelGrid columns="2" rendered="#{not empty dataModel.list}">
<h:commandLink immediate="true">
<p:commandButton value="Export excel" immediate="true" />
<p:dataExporter type="xls" target="barChart,tableResulta" fileName="formInformation" />
</h:commandLink>
<h:commandLink immediate="true">
<p:commandButton value="Export PDF" immediate="true" />
<p:dataExporter type="pdf" target="barChart,tableResulta" fileName="formInformation" />
</h:commandLink>
</h:panelGrid>
</h:form>
i have tried above code but not able to export both when i export only datatable then its work properly.
so please help me how can i export chart and datatable into signle file?
thanks in advances.
You just can't, not without creating a complex custom exporter... Sidenote: I think a real reporting tool is in the end a much better fit...
This is the XHTML code
<p:commandLink style="width: 10px;height: 10px;"
actionListener="#{InboxBean.archiveInboxRecord(actionEvent)}">
<img src="../resources/images/arch.png" />
<f:setPropertyActionListener value="#{inboxitem}"
target="#{InboxBean.selectedInbox}"/>
</p:commandLink>
and this is bean
public void archiveInboxRecord(ActionEvent actionEvent){
System.err.println("Record Title is " + this.selectedInbox.AppTitle);
}
An argument actionEvent do not require to send when you use actionListener. You should use the below code instead.
<p:commandLink style="width: 10px;height: 10px;"
actionListener="#{InboxBean.archiveInboxRecord}" >
<img src="../resources/images/arch.png" />
<f:setPropertyActionListener value="#{inboxitem}"
target="#{InboxBean.selectedInbox}" />
</p:commandLink>
Check if your datatable is in a form tag
like that :
<h:form id="form">
<p:datatable var="student" value="#{studentbean.listStd}">
<p:column headerText="column 1">Something here ..</p:column>
<p:column headerText="Action">
<p:commandLink style="width: 10px;height: 10px;"
actionListener="#{InboxBean.archiveInboxRecord}" >
<img src="../resources/images/arch.png" />
<f:setPropertyActionListener value="#{inboxitem}"
target="#{InboxBean.selectedInbox}" />
</p:commandLink>
</p:column>
</p:datatable>
</h:form>
Or try to put your commandLink in a from tag like that:
<h:form id="formLink">
<p:commandLink style="width: 10px;height: 10px;"
actionListener="#{InboxBean.archiveInboxRecord}" >
<img src="../resources/images/arch.png" />
<f:setPropertyActionListener value="#{inboxitem}"
target="#{InboxBean.selectedInbox}" />
</p:commandLink>
</h:form>
after friends aid ..
the right code is
<p:commandLink style="width: 10px;height: 10px;"
process="inboxdt"
actionListener ="#{InboxBean.archiveInboxRecord(actionEvent)}" >
<img src="../resources/images/arch.png" />
<f:setPropertyActionListener value="#{inboxitem}" target="#{InboxBean.selectedInbox}" />
</p:commandLink>
and the key solution is process the datatable Id "inboxdt"
I currently have a task to dynamically generate content that is now static. The problem is that the sessionScope variable from EL is used to toggle the rendering of content. Since sessionScope is a Map, I don't really know how to convert it to be used in a forEach loop.
Current layout:
<p:outputPanel layout="block">
<p:commandLink id="testId">
<p:graphicImage value="#{request.contextPath}/images/test.jpg" />
<f:setPropertyActionListener value="#{!sessionScope.renderContentA}" target="#{sessionScope.renderContentA}" />
</p:commandLink>
<pe:tooltip for="testId" value="TestTooltip" />
</p:outputPanel>
<p:outputPanel layout="block">
<p:commandLink id="testId2">
<p:graphicImage value="#{request.contextPath}/images/test2.jpg" />
<f:setPropertyActionListener value="#{!sessionScope.renderContentB}" target="#{sessionScope.renderContentB}" />
</p:commandLink>
<pe:tooltip for="testId2" value="TestTooltip" />
</p:outputPanel>
Which I need to convert to:
<c:forEach items="#{bean.items}" var="item">
<p:outputPanel layout="block">
<p:commandLink id="#{item.id}">
<p:graphicImage value="#{request.contextPath.concat(item.imageUrl)}" />
<f:setPropertyActionListener value="#{!SOMETHING-HERE}" target="#{SOMETHING-HERE}" />
</p:commandLink>
<pe:tooltip for="#{item.id}" value="TestTooltip" />
</p:outputPanel>
</c:forEach>
An example where it's used (which I need to adjust aswell):
<p:outputPanel autoUpdate="true" style="float: right;">
<p:commandLink rendered="#{!sessionScope.renderContentA}">
<h:outputText styleClass="ui-icon ui-icon-plus" />
<f:setPropertyActionListener value="#{!sessionScope.renderContentA}" target="#{sessionScope.renderContentA}" />
</p:commandLink>
<p:commandLink rendered="#{sessionScope.renderContentA}">
<h:outputText styleClass="ui-icon ui-icon-minus" />
<f:setPropertyActionListener value="#{!sessionScope.renderContentA}" target="#{sessionScope.renderContentA}" />
</p:commandLink>
</p:outputPanel>
I've been Googling for a while now, but can't find a good answer. I'm using Glassfish 4, Java EE 7, EL 3 and JSF 2.1.1-b04. If I need to provide something else, please let me know.
I found the sollution after some trial and error with a collegue. You can access sessionScope with a plain array-like approach.
<f:setPropertyActionListener value="#{!sessionScope[item.uniqueName]}" target="#{sessionScope[item.uniqueName]}" />