Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Richard Kosegi
Problem with form enctype="multipart/form-data"
November 11, 2012 5:29 AM
Answer

Richard Kosegi

Rank: New Member

Posts: 19

Join Date: September 5, 2011

Recent Posts

Hi liferay folks,

I have problem with such form.When I add enctype="multipart/form-data" to allow file uploads,
GetterUtil.getLong(actionRequest.getParameter("itemId")) returns allways zero (also title is empty).

Without enctype it works just fine, but I can not upload file.

What I'm missing in my code?

edit_item.jsp
 1
 2<%
 3long itemId = 10;
 4String title = "Test";
 5%>
 6
 7<liferay-portlet:actionURL name="updateItem" var="updateItemURL">
 8</liferay-portlet:actionURL>
 9
10    <aui:form action="<%= updateItemURL %>" method="post" name="fm" enctype="multipart/form-data">
11        <aui:input name="itemId" type="hidden" value="<%= String.valueOf(itemId) %>" />
12                <aui:input name="itemLogo" type="file" label="stock.item.label.file" />
13        <aui:button-row>
14            <aui:button class="aui-button-input" type="submit" value="<%= title  %>" />
15        </aui:button-row>            
16    </aui:form>


StockPortlet.java
 1
 2public void updateItem(ActionRequest actionRequest, ActionResponse actionResponse)
 3            throws IOException, PortletException {
 4       
 5        actionResponse.setRenderParameter("jspPage", "/jsp/stock/view_items.jsp");
 6
 7        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
 8        String title = GetterUtil.getString(actionRequest.getParameter("title"));
 9        long itemId = GetterUtil.getLong(actionRequest.getParameter("itemId"));
10
11        }
Richard Kosegi
RE: Problem with form enctype="multipart/form-data"
November 11, 2012 5:36 AM
Answer

Richard Kosegi

Rank: New Member

Posts: 19

Join Date: September 5, 2011

Recent Posts

OK, I figure it out.

I need to use this:

UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
long itemId = ParamUtil.getLong(uploadRequest,"itemId");

instead of

long itemId = GetterUtil.getLong(actionRequest.getParameter("itemId"));
josmar javier Alarcon Bothia
RE: Problem with form enctype="multipart/form-data"
April 10, 2013 8:21 AM
Answer

josmar javier Alarcon Bothia

Rank: New Member

Posts: 5

Join Date: February 11, 2013

Recent Posts

good morning, hey I have the same problem, implement what you commented on the UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest (ActionRequest), but I want to take the value of a text box, you know this to be due or q can happen ?
Manish Yadav
RE: Problem with form enctype="multipart/form-data"
April 10, 2013 9:16 AM
Answer

Manish Yadav

Rank: Expert

Posts: 384

Join Date: May 26, 2012

Recent Posts

Hi Bothia
Might be this code will help you

JSP
1
2public void sendEmail(ActionRequest request, ActionResponse response) {
3   UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
4   File file = uploadRequest.getFile("file");
5   String email = ParamUtil.getString(uploadRequest, "fromemail");
6}
giacomo savino
RE: Problem with form enctype="multipart/form-data"
January 29, 2014 5:00 AM
Answer

giacomo savino

Rank: Junior Member

Posts: 34

Join Date: June 16, 2011

Recent Posts

Manish Yadav:
Hi Bothia
Might be this code will help you

JSP
1
2public void sendEmail(ActionRequest request, ActionResponse response) {
3   UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
4   File file = uploadRequest.getFile("file");
5   String email = ParamUtil.getString(uploadRequest, "fromemail");
6}



Thank you