Liferay: how can i upload a image from portlet preferences? - java

Using liferay 6.2, I'm currently trying to create a portlet where a image is displayed.
I have already done this but I need to be able to change the image from the preferences uploading a new one. I already have a form to upload a file but I'm not able to upload the file and show it on the portlet.
This is the form in the edit.jsp
<aui:form action="<%=editPreferencesURL%>" method="post">
<aui:input label="image" name="Image" type="file"/>
<aui:button type="submit" />
</aui:form>
This is the renderURL:
<portlet:renderURL var="editPreferencesURL">
<portlet:param name="mvcPath" value="/html/folder/edit.jsp" />
</portlet:renderURL>

The editPreferencesURL that you mention is a renderURL - for posting a form you'll need an actionURL.
A renderURL is typically used to show the raw form (e.g. it's fine to use it to link to the edit mode form) but not for updating data. During render a portlet cannot change state, during action it can.

Related

Url with paramter as Button (Thymeleaf + Spring boot)

I'm using Spring Boot and Thymeleaf. A button should display the user another page if he clicks on the Button. The only problem I have is, the url needs a parameter.
I tried this, but this doesn't work:
<form th:action="#{/removeserver(id=${serverId})}">
<input type="submit" value="Remove server"/>
</form>
It works with the following link, but not as button:
<a th:text="Remove" th:href="#{/removeserver(id=${serverId})}"></a>
So how can I display a url with a parameter as a button?
I had similar problem so instead of using path-variable I used request-param:
<form action="archive?id=${x.id}" method="post">
<button type="submit">Archive</button>
</form>
You can try using this.

get the complete file path in Current jsp

Hi I wrote the below code in a jsp file to upload a file. But before I upload I want to display the entire path of the file in the current jsp itself
<form method="post" action="SendTheFileName">
<div id="Files_to_be_shared">
<input type="file" id="File" name="FileTag" />
<input type="submit" value="Share" />
</div>
Complete path of the file is <%=request.getParameter("File");%>//Is this correct?
I am not getting the complete path value. I get null instead. Can you please let me know how to get the complete path in the current jsp itself
Jsp's are made on the server and file is uploaded by user, in browser, by the time it will be uploaded - there will be no scriplets on your html page at all, meaning those parameter value will be tried to obtain during jsp creating, where it is obviously null(unless request really contains such value). To run code on the client use javascript, for example here is how to do what you want using javascript.
P.S. consider using EL, scriplets are considered harmful, there are plenty of info about this on the net

Struts2 text value displayed at incorrect position

I have created a struts2 login page, wherein I have all basic components necessary for login. I'm using struts2 text tag for a label. Below is my login page code snippet.
<body>
<h2>Demo - Login</h2>
<s:actionerror />
<s:form action="login.action" method="post">
<s:textfield name="username" key="label_username" size="20" />
<s:password name="password" key="label_password" size="20" />
<s:submit name="signIn" key="label_login" align="center" />
<s:text name="name_msg"/>
<s:submit name="signUp" key="label_signUp"></s:submit>
</s:form>
</body>
I always see that text(New to Demo ?) is displayed after heading, as shown in below Image. There text is read from MessageBundle. I tried by giving some direct text value, despite of referring to resource bundle, even though same result. Where I was wrong.
The <s:text> tag displays text with no "decoration".
The default "xhtml" theme's form tags emit table markup.
This means you're currently generating invalid HTML, so the text will show up in essentially arbitrary locations based on how the browser handles stuff showing up in between table rows.
Viewing the source would have answered this question immediately.
You need to either put the text into a table row, as with everything else in the form tag, or use the "simple" theme and do all the layout, error messages, etc. yourself.

servlet not found by the browser when it is there

I am trying to handle the form-data and put it in the data base derbi that comes with netbeans.The server i am using is Glassfish. After filling the form when i click the submit data button, according to the action handler the request should follow to a servlet named FormHandler.do but when i try to reach out to the page FormHandler.do this is the error message displayed by the browser :
This webpage is not found
No webpage was found for the web address:
file:///W:/UnderTest/WebApplication_GLASSFISH/src/java/FormHandler/FormHandler.do
Error 6 (net::ERR_FILE_NOT_FOUND): The file or directory could not be found.
But the file is there in the same directory as the html file (that has form). This is the type of url i give in the form tag:
<form method="post" action="FormHandler.do">
<b>Name:</b><input type="text" name="Name" /> <br /> <br />
<b>Email:</b><input type="email" name="Email" /> <br /> <br />
<b>Password:</b><input type="password" name="Password" /> <br /> <br />
<input type="submit" value="Register" />
What could be the reason for this problem ?
(After the request goes to the servlet FormHandler.do it checks (as per logic) if the text fields are empty. If they are empty it forwards the request to a servlet that shows the errors and if correct it inserts that data into the database and shows the success servlet.)
No webpage was found for the web address:
file:///W:/UnderTest/WebApplication_GLASSFISH/src/java/FormHandler/FormHandler.do
You need to access web resources by a HTTP path, not by a local disk file system path. Something like as:
http://localhost:8080/WebApplication_GLASSFISH/FormHandler.do
The /WebApplication_GLASSFISH part is the context path. It's unclear which one you're using, but this information is printed in the server's startup log. Something like as this:
INFO: WebApplication_GLASSFISH was successfully deployed in 3,770 milliseconds.
You need to make sure that the URL in your browser address bar matches this.
Also, HTML files should go in "Web Pages", not in "Source Packages". After you move the Registration.html into "Web Pages", you can open it by
http://localhost:8080/WebApplication_GLASSFISH/Registration.html
This way the form will submit to the proper servlet URL assuming that you've a
<form action="FormHandler.do">
This all is rather trivial. I'd suggest to go through a bit decent Servlet book/tutorial once again. Put your mouse above the servlets tag which you put below the question and click at the info link to get a good starting point.

JSP / servlet / IE combination doesn't submit form detail on Enter

Using IE 7, JDK 1.6 and Sun Web server 7.
Inside the jsp form, we have:
<input type="text" name="id" maxlength="20" />
<input ... type="submit" name="send" value="Send"/>
i.e. a text box and a "Submit" button (called Send).
and the servlet has:
if (request.getParameter("send") != null && request.getParameter("send").trim().length() > 0) { ... }
Using Fiddler and IE, we can see that the following is sent when we populate the id text box and hit Enter:
id=123456
However, using Fiddler and IE, we can see that the following is sent when we populate the id text box and click the Send button:
userId=123456&send=Send
The end result is that hitting the Enter key effectively does nothing.
On other jsp pages, e.g. we have:
<input type="text" name="id" maxlength="20" />
<input ... type="submit" name="submitId" value="Submit"/>
and the servlet has:
if (request.getParameter("submitId") != null && request.getParameter("submitId").trim().length() > 0) { ... }
Using Fiddler and IE, we can see that the following is sent for both cases:
id=123456&submitId=Submit
So it seems to us that the behaviour is only exhibited on IE for forms where the "Submit" button is not called "Submit"?
Re-running the tests on Firefox 3.6 shows that the behaviour is correct and the same for both cases.
Any suggestions for getting IE to work correctly?
(Note: I have searched SO for a similar problem but the questions relating to this mainly all ASP related!).
This is indeed another IE anomaly in case of forms with only one input field. The only solid workaround for this is to add a second input field(!). You can hide it using CSS. No, type="hidden" ain't going to work.
<input type="text" name="id" maxlength="20" />
<input type="text" style="display: none;" />
<input type="submit" name="send" value="Send"/>
Why are you checking for request.getParameter("submitId") in your JSP when in fact submitId is the name of your submit button?
In my experience I never had to check the value for the submit button. I only used that button to trigger the form submit and would usually only be interested in retrieving the values for the other form parameters.
If you want to differentiate the submit methods by the name of the submit button, you might want to try adding a "hidden" property using input type="hidden".

Categories