开发者

How to download file from inside Seam PDF

In out project we are creating a pdf by using seam pdf and storing that pdf in the database.

The user can then search up the pdf and view it in their pdf viewer. This is a small portion of the code that is generated to pdf:

<p:html>
<a:repeat var="file" value="#{attachment.files}" rowKeyVar="row">
<s:link action="#{fileHandler.downloadById()}" value="#{file.name}" >
    <f:param  name="fileId" value="#{file.id}"/>
</s:link>
</a:repeat>

When the pdf is rendered, a link is generated that points to:

/project/skjenkebevilling/status/status_pdf.seam?fileId=42&actionMethod=skjenkebevilling%2Fstatus%2Fstatus_pdf.xhtml%3AfileHandler.do开发者_开发知识库wnloadById()&cid=16

As you can see this link doesnt say much, and the servletpath seems to be missing.

If I change /project with the servletpath

localhost:8080/saksapp/skjenkebevilling/status/status_pdf.seam?fileId=42&actionMethod=skjenkebevilling%2Fstatus%2Fstatus_pdf.xhtml%3AfileHandler.downloadById%28%29&cid=16

Than the download file dialog appears. So my question is, does anyone know how I can input the correct link? And why this s:link doesnt seem to work?

If I cannot do that, then I will need to somehow do search replace and edit the pdf, but that seems like a bit of a hack.

(This is running under JBoss)

Thank you for your time....


I found a workaround for this problem. Seems I have to use s:link together with a normal a href tag. Only having href tag doesn't work for some reason.

<s:link action="#{fileHandler.downloadById()}" value="#{file.name}" propagation="none">
    <f:param name="fileId" value="#{file.id}"/>
</s:link>
<a href="#{servletPath.path}?fileId=#{file.id}&amp;actionMethod=#{path.replace('/','')}%2Fstatus%2Fstatus_pdf.xhtml%3AfileHandler.downloadById()&amp;">
    download
</a>

The servletPath.path returns the servlet path ie http://mydomain.com/download.seam You can decide to put login-required=true on the download.seam if you want users to login before downloading a file.

@Observer("org.jboss.seam.security.loginSuccessful")
public void servletPath() {
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    this.path = request.getRequestURL().toString().replace("login.seam", "download.seam");
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜