相关疑难解决方法(0)

commandButton/commandLink/ajax动作/侦听器方法未调用或输入值未设置/更新

有时,使用时<h:commandLink>,<h:commandButton>或者<f:ajax>,在action,actionListener或listener与标签相关的方法根本不被调用.或者,bean属性不会使用提交的UIInput值进行更新.

有什么可能的原因和解决方案?

jsf action commandlink jsf-2 commandbutton

332
推荐指数
5
解决办法
20万
查看次数

如何从JSF支持bean提供文件下载?

有没有办法从JSF支持bean动作方法提供文件下载?我尝试过很多东西.主要问题是我无法弄清楚如何获取OutputStream响应以便将文件内容写入.我知道如何使用a Servlet,但这不能从JSF表单调用,需要新的请求.

如何OutputStream从当前获得响应FacesContext?

jsf download jsf-2 backing-beans

85
推荐指数
2
解决办法
14万
查看次数

用JSF下载文件?

哪个是使用JSF下载文件的正确方法?只是放一个文件链接?在那种情况下我如何获得文件URL?

我见过一个使用BufferedInputStream的例子:

http://www.winstonprakash.com/articles/jsf/file_download_link.htm

有什么区别?

谢谢

java jsf download

15
推荐指数
2
解决办法
5万
查看次数

从Servlet访问JSF managedBean

我需要知道从servlet访问JSF managedBean(定义了应用程序范围)的最佳方法是什么.目前我的servlet中有这样的东西:

  MyApplicationScopeBean bean = null;
  try {
   FacesContext fContext = FacesUtil.getFacesContext(req, resp);
   ServletContext sc = (ServletContext) fContext.getExternalContext().getContext();
   bean = (MyApplicationScopeBean) sc.getAttribute("myManagedBean");   
  } catch (Exception e) {
   e.printStackTrace();
  }
Run Code Online (Sandbox Code Playgroud)

FacesUtil.java(如http://balusc.blogspot.com/2006/06/communication-in-jsf.html中所述):

import javax.faces.FactoryFinder;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContextFactory;
import javax.faces.lifecycle.Lifecycle;
import javax.faces.lifecycle.LifecycleFactory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FacesUtil {
    // Getters -----------------------------------------------------------------------------------
    public static FacesContext getFacesContext(
        HttpServletRequest request, HttpServletResponse response)
    {
        // Get current FacesContext.
        FacesContext facesContext = FacesContext.getCurrentInstance();
        // Check current FacesContext.
        if (facesContext == null) …
Run Code Online (Sandbox Code Playgroud)

jsf servlets javabeans

10
推荐指数
1
解决办法
2万
查看次数

POI - 将导出的文件保存到客户端

我正在将dataTable(绑定dataList)导出到excel文件,调用以下方法 xlsWorkBookPrepare("c:\\export.xls");

方法的一部分:

public void xlsWorkBookPrepare(String file) throws IOException
{
  /* prepare of workbook */
  Workbook wb = new HSSFWorkbook();
  Map<String, CellStyle> styles = Style.createStyles(wb);
  ... 

  for (FoodList item : dataList)
  { 
    ...
  }  

  /* create file */
  FileOutputStream fileOut;
  try 
  {
    fileOut = new FileOutputStream(file);
    wb.write(fileOut);
    fileOut.flush();
    fileOut.close();
  } 
  catch (FileNotFoundException e) 
  {
    e.printStackTrace();
  }  
}
Run Code Online (Sandbox Code Playgroud)

但路径与服务器有关.如何将它保存在客户端?

解决方案(基于Rangi Lin的回答):

HttpServletResponse res = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
res.setContentType("application/vnd.ms-excel");  
res.setHeader("Content-disposition",  "attachment; filename=test.xls"); 

try 
{
  ServletOutputStream fileOut = res.getOutputStream();
  wb.write(fileOut);
  fileOut.flush();
  fileOut.close();
} 
catch …
Run Code Online (Sandbox Code Playgroud)

java jsf apache-poi

3
推荐指数
1
解决办法
8127
查看次数