留言板

Problem with form enctype="multipart/form-data"

thumbnail
Richard Kosegi,修改在11 年前。

Problem with form enctype="multipart/form-data"

New Member 帖子: 19 加入日期: 11-9-5 最近的帖子
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

<%
long itemId = 10;
String title = "Test";
%>

<liferay-portlet:actionurl name="updateItem" var="updateItemURL">
</liferay-portlet:actionurl>

	<aui:form action="<%= updateItemURL %>" method="post" name="fm" enctype="multipart/form-data">
		<aui:input name="itemId" type="hidden" value="<%= String.valueOf(itemId) %>" />
                <aui:input name="itemLogo" type="file" label="stock.item.label.file" />
		<aui:button-row>
			<aui:button class="aui-button-input" type="submit" value="<%= title  %>" />
		</aui:button-row>			
	</aui:form>


StockPortlet.java

public void updateItem(ActionRequest actionRequest, ActionResponse actionResponse)
			throws IOException, PortletException {
		
		actionResponse.setRenderParameter("jspPage", "/jsp/stock/view_items.jsp");

		ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
		String title = GetterUtil.getString(actionRequest.getParameter("title"));
		long itemId = GetterUtil.getLong(actionRequest.getParameter("itemId"));

        }

thumbnail
Richard Kosegi,修改在11 年前。

RE: Problem with form enctype="multipart/form-data"

New Member 帖子: 19 加入日期: 11-9-5 最近的帖子
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,修改在11 年前。

RE: Problem with form enctype="multipart/form-data"

New Member 帖子: 6 加入日期: 13-2-11 最近的帖子
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 ?
thumbnail
Manish Yadav,修改在11 年前。

RE: Problem with form enctype="multipart/form-data"

Expert 帖子: 493 加入日期: 12-5-26 最近的帖子
Hi Bothia
Might be this code will help you

JSP

public void sendEmail(ActionRequest request, ActionResponse response) {
   UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
   File file = uploadRequest.getFile("file");
   String email = ParamUtil.getString(uploadRequest, "fromemail");
}
giacomo savino,修改在10 年前。

RE: Problem with form enctype="multipart/form-data"

Junior Member 帖子: 37 加入日期: 11-6-17 最近的帖子
Manish Yadav:
Hi Bothia
Might be this code will help you

JSP

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



Thank you
thumbnail
Asif Billa,修改在8 年前。

RE: Problem with form enctype="multipart/form-data"

New Member 帖子: 15 加入日期: 15-5-4 最近的帖子
Thanks Richard,

I was facing the same problem.
I applied your approach and it get solved. emoticon