
38.How to download PDF file with JSF?
This is an code example how it can be done with action listener of the backing bean.
Add the following method to the backing bean:
public void viewPdf(ActionEvent event) {
String filename = "filename.pdf";
// use your own method that reads file to the byte array
byte[] pdf = getTheContentOfTheFile(filename);
FacesContext faces = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)
faces.getExternalContext().getResponse();
response.setContentType("application/pdf");
response.setContentLength(pdf.length);
response.setHeader( "Content-disposition",
"inline; filename=\""+fileName+"\"");
try {
ServletOutputStream out;
out = response.getOutputStream();
out.write(pdf);
} catch (IOException e) {
e.printStackTrace();
}
faces.responseComplete();
}
This is a jsp file snippet:
39.How to show Confirmation Dialog when user Click the Command Link?h:commandLink assign the onclick attribute for internal use. So, you cannot use it to write your own code. This problem will fixed in the JSF 1.2. For the current JSF version you can use onmousedown event that occurs before onclick. function ConfirmDelete(link) { var delete = confirm(‘Do you want to Delete?’); if (delete == true) { link.onclick(); } } . . . . 40.What is the different between getRequestParameterMap() and getRequestParameterValuesMap()getRequestParameterValuesMap() similar to getRequestParameterMap(), but contains multiple values for for the parameters with the same name. It is important if you one of the components such as . 41.How to print out html markup with h:outputText?The h:outputText has attribute escape that allows to escape the html markup.
By default, it equals to “true”. It means all the special symbols will be replaced with ‘&’ codes.
If you set it to “false”, the text will be printed out without ecsaping.
For example, |