Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7015137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:36:46+00:00 2026-05-27T22:36:46+00:00

I have a JSF page, a drop down where values are getting fetched from

  • 0

I have a JSF page, a drop down where values are getting fetched from service.

<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 contains – abc, xyz

sampleService class

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);
    }
}

and there is an action button, which is used to generate a pdf based on the selection of type of value i.e. abc or xyz.

clicktoPdf button

<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();

    }

}

i need to generate pdf for the values selected from drop down. if “abc” is selected, it should call methodAbc(), if “xyz” is selected it should call
methodXyz().

Also the drop down list could contain more values – abc,xyz,pqr,rst etc etc. I know its not feasible to add method for every value in the drop down.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:36:47+00:00Added an answer on May 27, 2026 at 10:36 pm

    Create a private property:

    public class GeneratePdf {
        private String selectedValue;
        //getter/setter
    

    bind it to the selectonemenu:

    <h:selectOneMenu id="valueList" value="#{generatePdf.selectedValue}"
    

    On submission, the selectedValue will have the value selected on the drop down. You can use it in the pdfReport() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have JSF page has two drop down lists and I want to load
I have a JSF page that displays a RichFaces Treeview, from a TreeNodeImpl model
I have JSF code like: <h:inputText id=from value=#{fromToMBean.fromName}/> I would like to get this
I have the following line in a JSF page: <h:commandLink action=#{myBean.test} value=Wizard Step></h:commandLink> I
I have jsf page: .... <form jsfc=h:form action=> <h:dataTable value=#{newMusician.strings} var=preferredMusicGenre id=musicGenresSelectTable> <h:column> <h:inputText
In a create new user jsf page, I have a SelectOneMenu with a custom
I have a JSF page which is outputting XHTML (from a facelet). One of
I have the following dropdown in a Facelets page: <h:selectOneMenu value=#{contactBean.selectedContact} converter=#{contactConverter}> <f:selectItems value=#{contactsHolder.contacts}
I have a JSF page with a few fields. I followed this tutorial from
I have a JSF Page which gets few inputs from the User, I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.