Liferay - Image Gallery - java

Hello and thanks for taking the time to answer my question.
I have a custom portlet with a typical file upload html element. However, I was told that the user should be able to select already uploaded images and not upload new images. At the moment I am loading a web content display portlet on a random page, click on image icon in the rich text editor and copy the link in the javascript of my portlet, which opens the image gallery in a pop-up, in order to access the image gallery. However, this is not a plausible solution for production and I was wondering how I can load the image gallery from a custom portet. I need to be able to see the image gallery open in a pop-up with a user clicks Select an Image button.
Thanks in advance!

This code is enough to do this:
List<IGFolder> listIGFolders = null;
if(selectedFolderId!=0){
listIGFolders=IGFolderLocalServiceUtil.getFolders(groupId, selectedFolderId);
} else{
listIGFolders = IGFolderLocalServiceUtil.getFolders(groupId);
}
List<IGImage> igImages=IGImageLocalServiceUtil.getImages(groupId, selectedFolderId);

Related

Image link not showing image

I am using Java and Vaadin to create a simple view where an image is displayed. I have a single Image element containing a source link. Here is my code.
#Route(value = "")
public class MainView extends VerticalLayout {
public MainView() {
add(new Image("https://media.reaperscans.com/file/4SRBHm/comics/14659ab2-5650-4aaf-a5bb-9ad5a9828662/chapters/3aff6399-5ff4-46d1-b502-88788510d962/000.jpg", ""));
}
}
This compiles to a HTML in the browser containing an image element:
<img src="https://media.reaperscans.com/file/4SRBHm/comics/14659ab2-5650-4aaf-a5bb-9ad5a9828662/chapters/3aff6399-5ff4-46d1-b502-88788510d962/000.jpg">
When I open this image in new tab I can see the image correctly, but when I see it in my app there is only:
EDIT:
I can open the image using the link in Google Chrome.
If you open the image on Chrome you will notice the website doesn't allow hotlinking. That's why it doesn't load. Try using a different image (from Wikipedia, for example) and it should work well.
new Image("https://upload.wikimedia.org/wikipedia/commons/8/8e/Vaadin-flow-bakery.png","vaadin");
I recommend using the alt attribute as well, instead of leaving it empty as you had in your original question.

Have PDF appear in HTML rather than loading with Adobe or into separate window

I have a java web application that in theory, when working correctly, will display a PDF in the browser window next to some input text boxes so that an employee could index the document and store it away.
JSP URL: localhost:1234/Application
What is currently happening is this:
->User tells JSP to tell servlet to go into filesystem and grab a batch of PDFs
-->JSP displays which batch(folder) was grabbed, and the files contained inside the folder to the screen
EXAMPLE:
Folder1:
-document1 (button)
-document2 (button)
-document3 (button)
--->Person clicks on button that appears next to document name on the JSP and the servlet serves up the PDF data in a byte array as follows:
File file = new File(Dir + "\\" + batchName + "\\" + fileName);
byte[] by = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(by);
fis.close();
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment; filename=TheDocument." + "pdf");
response.getOutputStream().write(by);
response.getOutputStream().flush();
response.getOutputStream().close();
The PDF then opens in a SEPARATE WINDOW than what the application is running on, and the PDF file is downloaded to the machine into the downloads folder
What happens after this does not matter in the scope of this question.
What I WANT to happen is this:
User tells JSP to tell servlet to go into filesystem and grab a batch of PDFs
JSP displays which batch(folder) was grabbed, and the files contained inside the folder to the screen
Person clicks on button next to document name in the JSP and the servlet serves up the PDF document and loads it into the html page so that the person can view it in real time on the same window and do their indexing.
Changing the header to inline does not give me the desired effect as it loads the PDF in the same browser window, but only by clicking back can I get back to my JSP. It essentially loads up a whole new HTML/JSP window. The browser actually points right to my servlet in this case:
localhost:1234/Application/Servlet
Below is what I want the application to look like:
I've looked into several jquery plugins such as PDFObject, Colorbox and many others. I do not seem to get the desired effect that I want.
You could use pdf.js to render the pdf, with a Flash fallback for browser that aren't supported by pdf.js.
The helloworld example renders a pdf in a <canvas> element.
Whether a PDF opens in a separate application or in the browser is a setting in the browser, in Adobe, and in Windows Explorer (assuming Windows). You have no control over it, short of displaying your PDF in a Flash app, and then the user might not have Flash.
Not sure if this is what you are looking for but typically you can put a PDF in an iframe and have it opened up that way. The PDF just needs to be published on your server.
This answer may help you:
How to open a PDF file in an <iframe>?

How to show the content of a log file in new window when we click on a link in spring mvc

My main goal: When i click the link, a new browser window should be opened and displays the content of entire log file. And the window should not have an address bar and navigation buttons (Back, Forward).
Is there any approach to do this in Spring-MVC project?
Here is what i am doing now:
When i click the link, the controller will be called with a parameter logName.
Now the controller have access to get any kind of details of the log file like content, path, etc... I am setting all these details to an object and sending back to JSP.
Here i am not sure how to open a new window and display the content of the log file in that window.
Please suggest me an approach on this!!
It would be very helpful for me if you can share me with some examples...
Spring or JSP have nothing to do with it, the only way to force user's browser to open a link in a new tab is to use client-side Javascript. window.open() allows configuring the popup to hide certain interface elements (see all options in the documentation)
Your code would look something like:
<input type="button" value="Show Log" onclick="showLog(logName)">
function showLog(logName) {
var url = "/path-to-your-controller.html?logName=" + logName;
window.open(url, "LogPage", "toolbar=no,location=no,menubar=no");
}
However, I don't think using a customised browser popup is a good solution; it's been disappearing from the web for a reason. It would be more elegant to fetch raw data using AJAX and display it in a JS popup: it wouldn't interfere with user's page navigation (you tagged the question with jQuery, you could use jQuery UI for that).
What is more, I wouldn't be surprised if window.open wasn't supported by all browsers in the same way† - something to keep in mind if you're targeting a wider audience.
† seems that Chrome ignores location=no, for instance

Loading html only in Android webview

I only want to display html from a url and avoid loading images when a user clicks on any link on the webview. I have already set .setSupportMultipleWindows() to true. How do I accomplish this using loadDataWithBaseURL()?

jQuery dilemma in loading different pages on one page

Hello i need some help to figure out what to do .
I am trying to create a page that has a list of events and each time I click one of the list's elements a different photo gallery should load. I did this by loading each gallery in a different iframe.
The problem is that right now the only thing it dose is loading the first galery and the other ones don't seem to manage loading any pictures (if I refresh each frame than they work fine)
What should i do?
This is the script I used in the webpage
You can find the page source here http://www.avantsolutions.ro/exp.txt
You can try with jQuery UI Plugin instead of iFrame.
On clicking of list item(West pane), you can load center pane div with corresponding images.
Check the examples here.
You can use jQuery's load function to load a gallery via ajax.
$(selectorForYourGalleryDisplayDiv).load( url, [ data ], [ complete(responseText, textStatus, XMLHttpRequest) ] )
Load will take the result from url, if you need to pass it data it will use a HTTP POST, and replace the inner html of the wrapped set it is called on.
I don't know the internals of your architecture, but the main process is giving your galleries Ids, pass them to the server using the JSON format, your code will use that id to get what's needed for the gallery, render the html and return it.
load will drop that html into the elements that match selectorForYourGalleryDisplayDiv.

Categories

Resources