File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes JSF doubts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF doubts" Watch "JSF doubts" New topic
Author

JSF doubts

Govindarajan Srinivasan
Greenhorn

Joined: Nov 13, 2006
Posts: 1
1. How to invoke a servlet from js in a jsf environment?
while i invoke using

var slWindow = window.open("../InitServerServlet","","dialogWidth:815px;dialogHeight:390px;help:no;status:no;scroll:no;titlebar:no");

It is throwing Http 405 exception, Peage not found is displayed.
But I have an entry in the web.xml for the servlet.

2. Will it be possible to open a new window from a servlet and how?

3.I have to open a pdf from a server location and read as byte array and then i am again writing it as pdf , but I get illegal state exception, output stream already obtained ( Basically I need to print a pdf from the clinet side)


public class Test1 extends PageCodeBase {

protected HtmlForm TestForm;
protected HtmlCommandButton continueButton;
protected HtmlCommandButton printButton;

public String printAction()
{
try
{
downLoad("56456-ch09.pdf");
}
catch(Exception e)
{
e.printStackTrace();
}
return "";
}

protected void downLoad(String fileName)throws Exception
{
String fileType=null;
ServletOutputStream servletOutStream=null;
byte[] fileByteArray = createFileByteArray(fileName);
fileType=fileName.substring(fileName.lastIndexOf(".")+1);
try {
HttpServletResponse response = (HttpServletResponse)facesContext.getExternalContext().getResponse();
servletOutStream=response.getOutputStream();
if(fileType.equalsIgnoreCase("html")){
response.setContentType("application/html");
}else {
response.setContentType("application/pdf");
}
response.setHeader("Content-disposition", "inline;filename="+fileName+"\"");
//response.setHeader("Content-disposition", "attachment;filename="+fileName+"\"");
servletOutStream.write(fileByteArray);
} catch (Exception e) {
e.printStackTrace();

throw e;
}
finally{
try {
if(servletOutStream!=null){
servletOutStream.flush();
servletOutStream.close();
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
facesContext.responseComplete();
}

/**
* @param fileName
* @return
*/
public byte[] createFileByteArray(String fileName)throws Exception
{
byte[] fileByteArray = new byte[1024];
FileInputStream fileInputStream=null;
if(fileName!=null && !fileName.equals("")){
try{
String downLoadPath=Config.getString("form.upload.path","EM");
File downLoadFile= new File(downLoadPath+"\\"+fileName);
fileInputStream = new FileInputStream(downLoadFile);
int size =(int)downLoadFile.length();
fileByteArray = new byte[size];
fileInputStream.read(fileByteArray);

}catch(Exception exp){
exp.printStackTrace();
throw exp;
}
}
return fileByteArray;
}
 
wood burning stoves
 
subject: JSF doubts
 
Similar Threads
error locating file in servlet
downloading image
NullPointerException
Problem With Download File Servlet
Upload Download File