-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DocumentViewer: take file name from StreamedContent #796
Comments
Fixed with commit: primefaces-extensions/primefaces-extensions@27e2dd0 |
I just had a quick look at your commit, but isn't it giving precedence to Or else, remove the Just my 2 cents. |
I looked at else if (value instanceof String) {
src = ResourceUtils.getResourceURL(context, (String) value);
}
else if (value instanceof StreamedContent) {
StreamedContent streamedContent = (StreamedContent) value;
else {
byte[] bytes = toByteArray(streamedContent.getStream());
String base64 = DatatypeConverter.printBase64Binary(bytes);
return "data:" + streamedContent.getContentType() + ";base64," + base64; So it looks like build can take a String url, a StreamedContent, or a Base64 byteArray. I didn't want to make that assumption that is why i originally made it a |
Ok, I trust you, I just saw the following code in your commit: final Object value = documentViewer.getValue();
String downloadName = documentViewer.getDownload();
if (value instanceof StreamedContent) {
final StreamedContent streamedContent = (StreamedContent) value;
downloadName = streamedContent.getName();
}
return DynamicContentSrcBuilder.build(context, value, documentViewer,
documentViewer.isCache(), DynamicContentType.STREAMED_CONTENT, true) + "&download="
+ downloadName; This code seems to suggest |
right but your point was if you are providing a StreamContent you should use the file name of that streamed Content no? Not have to declare a |
My point was: the
OK for me, but then the documentation should be fixed, because it says exactly the opposite. |
Documentation and Taglib fixed: primefaces-extensions/primefaces-extensions@00a6f28 |
I think this change may have broken the link sent to download the PDF file. In the past the Example:
|
Can you post your streamed content code? I feel like you are missing the name in your StreamedContent? |
@jeromebridge I just tested this and my download was named "jack.pdf". content = DefaultStreamedContent.builder().stream(() -> new ByteArrayInputStream(out.toByteArray()))
.contentType("application/pdf").name("jack.pdf").build(); |
This is the code that creates the stream:
This is my XHTML component:
I don't think the Document Viewer can get its content from a "View Scoped" bean. So I put the content into the session and call the
|
Perfectly working example: Just unzip and run When you click Download you will see it is |
@melloware Thank you for the example. I see that you are using a "Request Scope" bean to generate the PDF. I'm using a "View Scoped" bean to generate the PDF. I don't think I can use the "Request Scope" bean to generate the PDF as you did. Do you have a way that I can use a "View Scope" bean to generate the PDF and get it to the Document Viewer component? |
I don't understand why you can't use |
Here is the answer from the master himself BalusC on why you can't use ViewScoped with Dynamic Streaming Content: https://stackoverflow.com/a/18994746/502366 You have to use RequestScoped or SessionScoped. |
@melloware I don't really want to put it in the session. That was the workaround I came up to provide a session scoped property to the component. I would like to (if possible) use the view scope to generate the PDF and make it accessible to the component somehow. |
Its not possible with Streaming if you read BalusC's stack overflow on why ViewScoped won't work. |
Just looking at the link you gave me. It appears they did something like this:
I tried to do something similar to see if I could get that identifier out of the request context:
I didn't see the parameter in the request context of the backing bean though. Just as a side note: That example is very similar to how I had it working in previous versions of primefaces / pf-extensions. |
Notice his bean is |
I agree (I know View Scoped doesn't work) I put my content parameter on a |
Not sure I am not even sure if what you are trying to do an pass the <f:param> is even possible with DocumentViewer. |
That's how From his example:
|
See #436 (comment)
When using the
pe:documentViewer
with aStreamedContent
instance, you have to use thedownload
attribute to specify the file name.This is completely unexpected:
StreamedContent
hasorg.primefaces.model.StreamedContent.getName()
whose purpose is exactly to provide the file name of the streamed content. This is howp:fileDownload
works, for instance.Perhaps the
download
attribute may be used to overrideStreamedContent.getName()
, but as a first choice I would expect theStreamedContent
instance to be enough to completely describe the document.The text was updated successfully, but these errors were encountered: