サービスから値が取得されるドロップダウンの JSF ページがあります。
<h:selectOneMenu id="valueList" value="#" style="height:20px;">
<f:selectItem itemValue="Select Action" itemLabel="Select Action" />
<f:selectItems value="#{sampleService.sampleMethod}"
var="SampleExport" itemValue="#{SampleExport}"
itemLabel="#{SampleExport}">
</f:selectItems>
</h:selectOneMenu>
exportlist には、abc、xyz が含まれています
sampleService クラス
public class SampleServiceImpl implements .... {
private List<String> sampleList;
public List<String> getSampleList;() {
return sampleList;
}
public void setSampleList;(List<String> sampleList;) {
this.sampleList=sampleList;;
}
/**
* Method for List to be displayed in drop down
*/
public void sampleMethod(){
if (sampleList== null) {
sampleList = new ArrayList<String>();
sampleList.add("abc");
sampleList.add("xyz");
}
setSsampleList(sampleList);
}
}
値のタイプ、つまりabcまたはxyzの選択に基づいてpdfを生成するために使用されるアクションボタンがあります。
clicktoPDF ボタン
<ui:define name="actions">
<h:commandButton styleClass="inputbutton" value="GeneratePdf" id="export"
action="#{generatePdf.pdfReport}" style="float:right;width : 73px;" />
</ui:define>
public class GeneratePdf {
public void pdfReport() {
..........
...code....
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
..........
.code..........
methodAbc(){
.....
}
method Xyz(){
......
}
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.setResponseContentType("application/vnd.ms-excel");
externalContext.setResponseHeader("Content-Disposition",
"attachment; filename=\"Sample Report\"");
workbook.write(externalContext.getResponseOutputStream());
facesContext.responseComplete();
}
}
ドロップダウンから選択した値の pdf を生成する必要があります。「abc」が選択されている場合は methodAbc() を呼び出す必要があり、「xyz」が選択されている場合は methodXyz() を呼び出す必要があります。
また、ドロップダウン リストには、abc、xyz、pqr、rst など、より多くの値を含めることができます。