Author |
Message |
20/12/2017 03:32:45
|
jtandarme
Active
Joined: 08/12/2017 06:21:34
Messages: 6
Offline
|
Why is it the pdf viewer does not work ?
here's the code below:
jsp:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib prefix="t" uri="/WEB-INF/eclnt"%>
<!-- ========== CONTENT BEGIN ========== -->
<f:view>
<h:form>
<f:subview id="PDFViewerg_sv">
<t:rowbodypane id="g_1" padding="0" >
<t:row id="g_2" >
<t:fileuploadbutton id="g_3" actionListener="#{d.PDFViewer.onNewMethod}" fileextensions="pdf" maxfilesize="5000000" text="Load PDF" />
</t:row>
<t:row id="g_4" >
<t:pdfrenderer id="g_5" bgpaint="rectangle(0,0,100%,100%,#000000A0,#00000040,vertical)" filename="{temp}/mypdf.pdf" height="100%" padding="top:10;bottom:5;left:10;right:10" pdf="#{d.PDFViewer.mypdf}" rendered="true" width="100%" withprintdialog="true" />
</t:row>
<t:rowstatusbar id="g_6" />
</t:rowbodypane>
<t:pageaddons id="g_pa"/>
</f:subview>
</h:form>
</f:view>
<!-- ========== CONTENT END ========== -->
java serverside:
package managedbeans;
import java.io.Serializable;
import org.eclnt.editor.annotations.CCGenClass;
import org.eclnt.jsfserver.defaultscreens.Statusbar;
import org.eclnt.jsfserver.elements.events.BaseActionEventUpload;
import org.eclnt.jsfserver.elements.util.Trigger;
import org.eclnt.jsfserver.managedbean.IDispatcher;
import org.eclnt.jsfserver.pagebean.PageBean;
import org.eclnt.jsfserver.util.WebResourceReader;
import org.eclnt.util.file.FileManager;
import org.eclnt.util.valuemgmt.ValueManager;
import javax.faces.event.ActionEvent;
@CCGenClass (expressionBase="#{d.PDFViewer}")
public class PDFViewer
extends PageBean
implements Serializable
{
protected String m_mypdf;
public String getMypdf(){return m_mypdf;}
public void setMypdf(String value){this.m_mypdf = value;}
byte[] bytes;
public byte[] getBytes(){return bytes;}
public void setBytes(byte[] value){this.bytes = value;}
public void onNewMethod(javax.faces.event.ActionEvent event) {
try{
if (event instanceof BaseActionEventUpload) {
BaseActionEventUpload base = (BaseActionEventUpload) event;
bytes = base.getHexBytes();
m_mypdf = ValueManager.encodeHexString(bytes);
}
}catch (Throwable throwable){
throwable.toString();
}
}
// ------------------------------------------------------------------------
// inner classes
// ------------------------------------------------------------------------
/* Listener to the user of the page bean. */
public interface IListener
{
}
// ------------------------------------------------------------------------
// members
// ------------------------------------------------------------------------
private IListener m_listener;
// ------------------------------------------------------------------------
// constructors & initialization
// ------------------------------------------------------------------------
public PDFViewer() {
}
public String getPageName() { return "/PDFViewer.jsp"; }
public String getRootExpressionUsedInPage() { return "#{d.PDFViewer}"; }
// ------------------------------------------------------------------------
// public usage
// ------------------------------------------------------------------------
/* Initialization of the bean. Add any parameter that is required within your scenario. */
public void prepare(IListener listener)
{
m_listener = listener;
}
// ------------------------------------------------------------------------
// private usage
// ------------------------------------------------------------------------
}
thanks for the help
|
|
|
20/12/2017 03:38:59
|
jtandarme
Active
Joined: 08/12/2017 06:21:34
Messages: 6
Offline
|
here's the screenshot of the output, nothings gonna happen when I click the load pdf button to choose pdf file.
|
Filename |
Untitled.png |
Download
|
Description |
here's the screenshot of the output, nothings gonna happen when I click the load pdf button to choose pdf file. |
Filesize |
70 Kbytes
|
Downloaded: |
206 time(s) |
|
|
|
20/12/2017 04:56:38
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5528
Offline
|
You code works - with small PDF files!
The control that you use (FILEUPLOADBUTTON) embeds the content to be uploaded into its call to the server, or in technical terms: it is part of the POST-request to the server, just as e.g. a normal text that the user keys in into a field.
Tomcat has a configuration about the max post size in its server.xml file. This is by default (I believe) something like 1MB. Because files are embedded as hexadecimal String the max PDF file size is 50% of this, i.e. 0.5MB.
Please tell Tomcat, that you require longer post size:
Code:
<Connector port="50000" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="50001"
maxPostSize="-1"/>
Defining "-1" means "unrestricted".
Regards, Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
20/12/2017 13:31:32
|
jtandarme
Active
Joined: 08/12/2017 06:21:34
Messages: 6
Offline
|
Hi,
Thanks a lot Bjorn, My code is working I just need to run it into separate dialog box. And you're right it is only intended for short file size. I was not yet try the code that you have given to upload a larger size.
Another question, I have a fileupload button in my row in the grid and when I try to click the button, the current row of the grid is not being highlighted, only the file browser will popup. Is there any way that when I click the fileupload button,
the file browser will popup and at the same time the current row will be also highlighted?
|
|
|
|