掲示板
Parameter not receive from controller class
10年前 に Yar Zar によって更新されました。
Parameter not receive from controller class
New Member 投稿: 18 参加年月日: 14/04/07 最新の投稿
Hi All,
I have a problem while i try to send the parameter within the same form of image <aui:input label="Price" name="phonePrice" type="text" > and <input name="filesToUpload" id="filesToUpload" type="file" multiple />. It is not sending phonePrice parameter if i put enctype="multipart/form-data" from aui:form tab. If i remove enctype="multipart/form-data" then the file(filesToUpload) not sending. Please advise.
My JSP page.
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@ page import="com.liferay.portal.kernel.util.Validator"%>
<%@ page import="javax.portlet.PortletPreferences"%>
<%@ page import="com.liferay.util.PwdGenerator"%>
<portlet:defineObjects />
<%
String uploadProgressId = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
PortletPreferences prefs = renderRequest.getPreferences();
%>
<portlet:actionURL var="editCaseURL" name="uploadCase">
<portlet:param name="mvcView" value="/view.jsp" />
</portlet:actionURL>
<liferay-ui:success key="success" message=" Uploaded successfully!" />
<liferay-ui:error key="error"
message="Sorry, an error prevented the upload. Please try again." />
<liferay-ui:upload-progress
id="<%= uploadProgressId %>"
message="uploading"
redirect="<%= editCaseURL %>"
/>
<aui:form action="<%= editCaseURL %>" method="post" name="fm" onSubmit='<%= "event.preventDefault(); " + renderResponse.getNamespace() + "savesaveTest();" %>'
enctype="multipart/form-data">
</aui:form>
<aui:form action="<%= editCaseURL %>" enctype="multipart/form-data" method="post" >
<div>
<span class="aui-field-label"> TestImages </span>
</div>
<div>
<input name="filesToUpload" id="filesToUpload" type="file" multiple />
</div>
<aui:input label="Price" name="phonePrice" type="text" >
<aui:validator name="digit" />
<aui:validator name="maxLength">10</aui:validator>
</aui:input>
<input type="submit" value="<liferay-ui:message key="upload" />" onClick="<%= uploadProgressId %>.startProgress(); return true;"/>
<!-- aui:button type="submit" value="Save" /-->
</aui:form>
<aui:script>
function <portlet:namespace />saveTest() {
submitForm(document.<portlet:namespace />fm);
}
</aui:script>
I have a problem while i try to send the parameter within the same form of image <aui:input label="Price" name="phonePrice" type="text" > and <input name="filesToUpload" id="filesToUpload" type="file" multiple />. It is not sending phonePrice parameter if i put enctype="multipart/form-data" from aui:form tab. If i remove enctype="multipart/form-data" then the file(filesToUpload) not sending. Please advise.
My JSP page.
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@ page import="com.liferay.portal.kernel.util.Validator"%>
<%@ page import="javax.portlet.PortletPreferences"%>
<%@ page import="com.liferay.util.PwdGenerator"%>
<portlet:defineObjects />
<%
String uploadProgressId = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
PortletPreferences prefs = renderRequest.getPreferences();
%>
<portlet:actionURL var="editCaseURL" name="uploadCase">
<portlet:param name="mvcView" value="/view.jsp" />
</portlet:actionURL>
<liferay-ui:success key="success" message=" Uploaded successfully!" />
<liferay-ui:error key="error"
message="Sorry, an error prevented the upload. Please try again." />
<liferay-ui:upload-progress
id="<%= uploadProgressId %>"
message="uploading"
redirect="<%= editCaseURL %>"
/>
<aui:form action="<%= editCaseURL %>" method="post" name="fm" onSubmit='<%= "event.preventDefault(); " + renderResponse.getNamespace() + "savesaveTest();" %>'
enctype="multipart/form-data">
</aui:form>
<aui:form action="<%= editCaseURL %>" enctype="multipart/form-data" method="post" >
<div>
<span class="aui-field-label"> TestImages </span>
</div>
<div>
<input name="filesToUpload" id="filesToUpload" type="file" multiple />
</div>
<aui:input label="Price" name="phonePrice" type="text" >
<aui:validator name="digit" />
<aui:validator name="maxLength">10</aui:validator>
</aui:input>
<input type="submit" value="<liferay-ui:message key="upload" />" onClick="<%= uploadProgressId %>.startProgress(); return true;"/>
<!-- aui:button type="submit" value="Save" /-->
</aui:form>
<aui:script>
function <portlet:namespace />saveTest() {
submitForm(document.<portlet:namespace />fm);
}
</aui:script>
10年前 に Juan Gonzalez によって更新されました。
RE: Parameter not receive from controller class
Liferay Legend 投稿: 3089 参加年月日: 08/10/28 最新の投稿
Can you post here your controller method where you are retrieving those params?
10年前 に Yar Zar によって更新されました。
RE: Parameter not receive from controller class
New Member 投稿: 18 参加年月日: 14/04/07 最新の投稿
Hi Juan, Sushil,
Thanks for suggest. Please see following code. I can get the file name and i can successfully upload the file with following code when i put enctype="multipart/form-data" in form tab however i can't get phonePrice parameter. If i remove enctype="multipart/form-data" from form tab then i can get phonePrice parameter but can't get file parameter.
MyController.java
public void uploadCase(ActionRequest actionRequest,
ActionResponse actionResponse) throws PortletException,
IOException {
long folderNameID=102;
long folderId=0;
String phonePrice=ParamUtil.getString(actionRequest, "phonePrice");
logger.info("phonePrice ::: "+phonePrice);
try {
folderId = addFileEntry(actionRequest, folderNameID);
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch ( SystemException e) {
e.printStackTrace();
}
logger.info("folderId Before put to request : "+folderId);
actionResponse.setRenderParameter("folderId", String.valueOf(folderId));
actionResponse.setRenderParameter("jspPage",actionRequest.getParameter("mvcView"));
}
public long addFileEntry(ActionRequest actionRequest, long folderNameID)
throws IOException, PortalException, SystemException {
String fileToUpload="filesToUpload";
long fileEntryId=0;
UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
com.liferay.portal.theme.ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest
.getAttribute(WebKeys.THEME_DISPLAY);
String[] sourceFileName = uploadPortletRequest.getFileNames(fileToUpload);
File[] files = uploadPortletRequest.getFiles(fileToUpload);
InputStream[] filesStream = uploadPortletRequest.getFilesAsStream(fileToUpload);
for (String fileName : sourceFileName) {
logger.info("SourceFileName : "+fileName);
}
...
...
...
...
...
...
...
return folderId;
}
Thanks for suggest. Please see following code. I can get the file name and i can successfully upload the file with following code when i put enctype="multipart/form-data" in form tab however i can't get phonePrice parameter. If i remove enctype="multipart/form-data" from form tab then i can get phonePrice parameter but can't get file parameter.
MyController.java
public void uploadCase(ActionRequest actionRequest,
ActionResponse actionResponse) throws PortletException,
IOException {
long folderNameID=102;
long folderId=0;
String phonePrice=ParamUtil.getString(actionRequest, "phonePrice");
logger.info("phonePrice ::: "+phonePrice);
try {
folderId = addFileEntry(actionRequest, folderNameID);
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch ( SystemException e) {
e.printStackTrace();
}
logger.info("folderId Before put to request : "+folderId);
actionResponse.setRenderParameter("folderId", String.valueOf(folderId));
actionResponse.setRenderParameter("jspPage",actionRequest.getParameter("mvcView"));
}
public long addFileEntry(ActionRequest actionRequest, long folderNameID)
throws IOException, PortalException, SystemException {
String fileToUpload="filesToUpload";
long fileEntryId=0;
UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
com.liferay.portal.theme.ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest
.getAttribute(WebKeys.THEME_DISPLAY);
String[] sourceFileName = uploadPortletRequest.getFileNames(fileToUpload);
File[] files = uploadPortletRequest.getFiles(fileToUpload);
InputStream[] filesStream = uploadPortletRequest.getFilesAsStream(fileToUpload);
for (String fileName : sourceFileName) {
logger.info("SourceFileName : "+fileName);
}
...
...
...
...
...
...
...
return folderId;
}
10年前 に sushil patidar によって更新されました。
RE: Parameter not receive from controller class
Expert 投稿: 467 参加年月日: 11/10/31 最新の投稿
Hi,
In the controller you are getting "phonePrice" from simple actionRequest . Get the paramater using "uploadRequest" as follows.
In the controller you are getting "phonePrice" from simple actionRequest . Get the paramater using "uploadRequest" as follows.
String phonePrice= ParamUtil.getString(uploadPortletRequest, "phonePrice", StringPool.BLANK);
10年前 に Yar Zar によって更新されました。
RE: Parameter not receive from controller class
New Member 投稿: 18 参加年月日: 14/04/07 最新の投稿
Hi,
Sorry for wrong info. I retest again and phonePrice parameter is not sending with or without enctype="multipart/form-data".
Thanks
Sorry for wrong info. I retest again and phonePrice parameter is not sending with or without enctype="multipart/form-data".
Thanks
10年前 に Juan Gonzalez によって更新されました。
RE: Parameter not receive from controller class
Liferay Legend 投稿: 3089 参加年月日: 08/10/28 最新の投稿
What Liferay version are you using?
10年前 に Yar Zar によって更新されました。
RE: Parameter not receive from controller class
New Member 投稿: 18 参加年月日: 14/04/07 最新の投稿
Hi Sushil, Juan,
Thank you. I got the param value as per your advise of following code. I am using liferay 6.2. Thanks
String phonePrice= ParamUtil.getString(uploadPortletRequest, "phonePrice", StringPool.BLANK);
Thank you. I got the param value as per your advise of following code. I am using liferay 6.2. Thanks
String phonePrice= ParamUtil.getString(uploadPortletRequest, "phonePrice", StringPool.BLANK);
9年前 に Ishani Sheth によって更新されました。
RE: Parameter not receive from controller class
New Member 投稿: 14 参加年月日: 14/09/09 最新の投稿
Hii,
I have referred your solution of using uploadPortletRequest and it also resolved my problem but I am not getting why ParamUtil.getString(actionRequest,"stringname") does not work? And why we need this uploadPortletRequest?
Thanks ,
Ishani Sheth
I have referred your solution of using uploadPortletRequest and it also resolved my problem but I am not getting why ParamUtil.getString(actionRequest,"stringname") does not work? And why we need this uploadPortletRequest?
Thanks ,
Ishani Sheth
9年前 に Manali Lalaji によって更新されました。
RE: Parameter not receive from controller class
Expert 投稿: 362 参加年月日: 10/03/09 最新の投稿
Hi,
You can't get values from actionRequest if you are trying to upload multipart contant like file.
If your HTML Form's enctype is "multipart/form-data" then you need to use UploadPortletRequest and if your from is just a simple html form you can use ParamUtil.
HTH!
You can't get values from actionRequest if you are trying to upload multipart contant like file.
If your HTML Form's enctype is "multipart/form-data" then you need to use UploadPortletRequest and if your from is just a simple html form you can use ParamUtil.
HTH!
10年前 に sushil patidar によって更新されました。
RE: Parameter not receive from controller class
Expert 投稿: 467 参加年月日: 11/10/31 最新の投稿
Hi,
In case of enctype="multipart/form-data" , you should get parameters from upload request as follows.
Regards
In case of enctype="multipart/form-data" , you should get parameters from upload request as follows.
UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
File file = uploadPortletRequest.getFile("filesToUpload");
String phonePrice= ParamUtil.getString(uploadPortletRequest, "phonePrice", StringPool.BLANK);
Regards