开发者

JSF Seam @RequestParameter File/Image

i have a Backing Bean in which i read parameter which are not bound to a component. Seam offered that to read get parameter. I used

@RequestParameter private String param1;

this way he doesn't skip my action method on a validation error, like when i used <param name="param1" value="#{myBean.param1}" /> , because i don't want to render HTML responses but reuse the business logic. Instead i grab the response stream and write the rendered response myself

FacesContext ctx = FacesContext.getCurrentInstance();

final HttpServletResponse resp = (HttpServletResponse)ctx.getExternalContext().getResponse();      
resp.getOutputStream().write(xml.getBytes());
resp.getOutputStream().flush();
resp.getOutputStream().close();

ctx.responseComplete(); // render response phase done

I tried to read the file from the HttpServletRequest inputStream but that was already empty. Is there a way to still get the "file" from JSF. I could use a separate servlet and handle it there, but that would break a little bit how i build the rest of开发者_开发问答 the interface.

Thx for any advice.

Edit: Just for completeness the code for the input stream

final HttpServletRequest request = (HttpServletRequest)ctx.getExternalContext().getRequest();
ServletInputStream stream = request.getInputStream();
int byt = stream.read(); // byt was -1

Edit Edit: Sorry for the long post. Now i made a separate servlet. There i also get an empty input Stream even though Firefug said i transmitted the file. How can that be empty?

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

boolean isMultipart = ServletFileUpload.isMultipartContent(req);
ServletInputStream stream= req.getInputStream();
int test = stream.read(); // test == -1

That servlet code works fine in a separate project, so one of the JSF/Seam servlets in the filter chain has to remove the data. If someone has a hint which one or how to check.


The SeamFilter or more exactly the MultipartFilter was checking every request if it is a POST and multipart request. If so, they wrapped the request in a MultipartRequest and put the files in a separate parameter map.

final HttpServletRequestWrapper request = (HttpServletRequestWrapper)FacesContext.getCurrentInstance().getExternalContext().getRequest();
final ServletRequest innerRequest = request.getRequest();
if(innerRequest instanceof MultipartRequest){
    byte[] imageData = ((MultipartRequest)innerRequest).getFileBytes("image");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜