Based on the selection of a few form elements, I want to dynamically load a PDF file into an embed/object tag which is stored in a database.
Serving the PDF
I found this solution to serve a PDF from a servlet.
Is this the right approach when using Facelets? Because I thought when using facelets, I shouldn't need Servlets so how would I do that with a Bean?
As I load the PDF dynamically from a Database, I don't have access to a file on the file-system so in which way would I have to modify the response.setHeader?
Call from JSF
I thought that I would somehow first trigger a javascript function to update the content of the src attribute in the embed tag and then with the ajax tag from the jsf core library trigger the rerendering of the embed element.
Is this the right approach?
<embed src="#{pdfServlet.getPdf[desiredFileId]}"></embed>
Related
I have two servers. Server-webapplication-1 builed by primefaces+liferay, Server-2 builed spring-boot rest API, the server-2 to do something and return a pdf file (i was referred link https://www.technicalkeeda.com/spring-tutorials/download-pdf-file-using-spring-mvc-rest-controller).
In web-application, i have a p:commandLink onclick will get PDF file from server-2 and pass the PDF file to server-webapplication-1. If the PDF file is small (<10Mb), i cant encode to base64 and pass it (How to pass a blob created in javascript to JSF bean). If the PDF file is big, i don't know how to do that because java-exception will be throught (java heap space).
So, how to pass a big file to jsf bean from javascript?
I'm trying to create a CSS documentation library in Orchard. I want to save a description, CSS snippet and HTML snippet against each content type. The first view would show the description and CSS and HTML code written out. The second view would show a preview of what the CSS and HTML look like rendered.
cssdocumentation.com/content/item1
cssdocumentation.com/content/item1/live-preview
I've created the content type and the first view. But I'm not sure how to create the second view. I can see if I can create the alternative URL I can use the Url Alternates module to create an overriding .cshtml
To create an alternative URL I've looked at the autoroute module but this only allows you to adapt a single URL (unless I'm missing something?) and I've looked at Alias UI but this forces me to manually create an alternative URL everytime I create a content item.
Is this possible in Orchard without writting too much C#? (I'm a frontend developer so I only dabble in the behind the scenes stuff)
Thanks for any help
Best solution is to do this within your own module. But as a secondary option instead of having a second page, combine this content with your first page and hide it with CSS. When the user clicks a button to navigate to the next step render the CSS/HTML result on the same page. You can do this in many ways, here are a few ideas:
Render the CSS/HTML result out straight away on the same page but hide it. Show it when the user clicks a button
using jQuery to render the result on the client side. More dynamic if you allow editing of the HTML and CSS.
Redirecting the user to the same page with specific url parameters which you can pick up in your alternate to modify the output.
How can I embed an external JavaScript library like Google maps within a JSF view?
In traditional HTML I'd do it like <script src="http://maps.google.com/maps/api/js?v=3.6&sensor=false"></script>.
I want to know if its compulsory to use < h:outputScript> tag when I want to include an external JS library in a JSF view, because all examples I was able to find on this subject assumed that the actual JS file was included in a web application project and thus used <h:outputScript>.
You can insert standard HTML elements in your JSF views, like <div> or <script>, as in your case. Moreover, JSF will ultimately render <h:outputScript> as a plain <script> element. We normally use the former to let the JS file pass through the FacesServlet.
All of this yields that your <script> element shall be inserted 'as is'.
I am creating a hook in which i want to add my image in custom jsp.
I have added image inside docroot/images/1.jpg
in jsp i am trying to access it using
<img src="<%=request.getContextPath()%>/images/1.jpg" />
but i am not able to get image.
Additionally when i am trying to print <%=request.getContextPath()%> is only prints "/"
Thanks !!!
Instead of taking images from your war (docroot folder), suggest you to place the images in a Web server so that in future you can easily replace them if you want to change images.
You could use below code in your jsp page to retrieve from Web server,
<div class="yourCSSClass">
<liferay-ui:icon src="/yourWebServerPath/1.jpg" label="" message=""/>
</div>
Another flavour of it,
In your JSP page if you have below code,
<nav class="yourCSSClass"><br/><br/></nav>
Then, in the CSS file that you are importing in your JSP page, use this,
.yourCSSClass{
background: url(yourWebServerPath/1.jpg) no-repeat;
}
P.S : In both the above examples, decide properly the value for yourWebServerPath
Very old question, but still worth answering.
Your hook replaces portal’s JSPs with your owns but that doesn’t mean that the context of the new JSPs is your hook’s one.
What actually happens is that JSPs are replaced at the File System level, and called by other Liferay JSPs and configuration as they were the original one.
The request you have access to, therefore, is the main and original one.
As far as I know, there’s no clean way to get the context path of the hook that is providing an overriding JSPs.
I am trying to use tomahawk MyFaces file upload component t:inputFileUpload. I followed the example at JSF 2.0 File upload, with one change-instead of copying files to /lib, I used maven. There are no errors or warnings, but the file upload component is not showing up. Only the submit button shows on the screen. Please help me
Check the rendered HTML page. Perhaps it still contains <t:inputFileUpload>. In this case you may have forgotten to add the namespace for the prefix t to your file like this:
xmlns:t="http://myfaces.apache.org/tomahawk"
If the prefix isn't defined, the tags are simply not processed and directly rendered to the output.