Rog*_*ons 5 media pdf lightbox primefaces
我正在使用<p:lightBox>流式编程<p:media>来预览外部 PDF。
它工作得很好,但我遇到了一点障碍。
当 pdf 对话框呈现时,它会显示(鼠标悬停时)一个标题,其中始终显示相同的标题:“dynamiccontent.properties”。
是否有一个属性或其他东西我可以覆盖来自定义它?
JSP代码:
<p:lightBox>
<h:outputLink value="#" title="#{myDoc.fileName}">
<i class="fa fa-eye" aria-hidden="true"></i>
</h:outputLink>
<f:facet name="inline">
<p:media value="#{documentController.stream}" width="1100px" height="600px" player="pdf">
<f:param name="idStore" value="#{myDoc.idStore}" />
</p:media>
</f:facet>
</p:lightBox>
Run Code Online (Sandbox Code Playgroud)
谢谢你的时间。
小智 1
我在使用谷歌浏览器时遇到了同样的问题。
标题不会出现在 IE 11 中。
(我只使用 IE 11 和 Google Chrome,所以我不知道这在其他浏览器上是什么样子)
这是media使用流式值渲染的样子:
<object type="application/pdf"
data="/projectName/javax.faces.resource/dynamiccontent.properties.xhtml?ln=primefaces&v=6.1&pfdrid=a754229fe5cdabff72537ef0693a2399&pfdrt=sc&pfdrid_c=true"
height="600px" width="1100px" internalinstanceid="6">
</object>
Run Code Online (Sandbox Code Playgroud)
/projectName/javax.faces.resource/dynamiccontent.properties.xhtml来自DynamicContentSrcBuilder#build(resourcePath)
我努力了:
1.设置名称DefaultStreamedContent
new DefaultStreamedContent(getData(), "application/pdf", "test.pdf");
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用。name 在中变为 null,MediaRenderer#encodeEnd因此名称不会添加到 中src。
if (streamedContent.getName() != null) {
int index = src.indexOf("?");
src = src.substring(0, index) + ";/" + streamedContent.getName() + ""
+ src.substring(index, src.length());
}
Run Code Online (Sandbox Code Playgroud)
2.覆盖MediaRenderer#encodeEnd并添加固定值名称(Test.pdf)
if ((value != null) && (value instanceof StreamedContent) && (player.getType().equals("application/pdf"))) {
streamedContent = (StreamedContent) value;
if (streamedContent.getName() != null) {
int index = src.indexOf("?");
src = src.substring(0, index) + ";/" + streamedContent.getName() + ""
+ src.substring(index, src.length());
}
src = src.substring(0, index) + ";/Test.pdf"
+ src.substring(index, src.length());
}
Run Code Online (Sandbox Code Playgroud)
这也没有奏效。lightBox 打开但无法显示 pdf 文件。
3.使用 xhtml 中设置的值覆盖MediaRenderer#encodeEnd并替换“dynamiccontent.properties”中的值src
。title
MediaRenderer#encodeEnd
if ((value != null) && (value instanceof StreamedContent) && (player.getType().equals("application/pdf"))) {
streamedContent = (StreamedContent) value;
if (streamedContent.getName() != null) {
int index = src.indexOf("?");
src = src.substring(0, index) + ";/" + streamedContent.getName() + ""
+ src.substring(index, src.length());
}
if (src.contains("dynamiccontent.properties")) {
String[] urlParams = src.split("&");
for (String param : urlParams) {
if (param.contains("title=")) {
String[] titleAndValue = param.split("=");
src = src.replace("dynamiccontent.properties", titleAndValue[1]);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
html
<p:lightBox>
<h:outputLink value="#" title="#{myDoc.fileName}">
<i class="fa fa-eye" aria-hidden="true"></i>
</h:outputLink>
<f:facet name="inline">
<p:media value="#{documentController.stream}" width="1100px" height="600px" player="pdf">
<f:param name="title" value="Test.pdf" />
</p:media>
</f:facet>
</p:lightBox>
Run Code Online (Sandbox Code Playgroud)
rededmedia看起来像这样。
<object type="application/pdf"
data="/projectName/javax.faces.resource/Test.pdf.xhtml?ln=primefaces&v=6.1&pfdrid=a754229fe5cdabff72537ef0693a2399&pfdrt=sc&title=Test.pdf&pfdrid_c=true"
height="600px" width="1100px" internalinstanceid="6">
<param name="title" value="Test.pdf">
</object>
Run Code Online (Sandbox Code Playgroud)
这有效,但仅适用于StreamedContent. 以下是 pdf 标题的屏幕截图。
请注意,“.xhtml”是必需的。没有它它就无法工作。
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
7698 次 |
| 最近记录: |