Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Giuliane Monteiro
problems to get a checkbox value in action
March 17, 2011 7:21 AM
Answer

Giuliane Monteiro

Rank: New Member

Posts: 12

Join Date: March 6, 2011

Recent Posts

Hi people.

I try to get a value from checkbox in my jsp but it's not work.

I try to get the value this way.

<form
action="<liferay-portlet:actionURL name="editImageInit" />"
enctype="multipart/form-data" method="post"
name="<portlet:namespace />fm"
onSubmit="<portlet:namespace />editImageInit(); return false;">


<p><input name="imageId" type="checkbox" value="<%=igImage.getLargeImageId()%>" /> <img
src="/image/image_gallery?img_id=<%=igImage.getLargeImageId()%>"
width="100" height="100" /></p>


<%
}
}
%> <input type="submit"
value="<liferay-ui:message key="admPopUp.message.editar" />" /></form>

<aui:script>
function <portlet:namespace />editImageInit() {

for(var i=0; i< document.<portlet:namespace />fm.length; i++){

if(document.<portlet:namespace />fm.imageId.checked == true){

document.<portlet:namespace />fm.<portlet:namespace />imageId.value = document.<portlet:namespace />fm.<portlet:namespace />imageId.value;

}
}
submitForm(document.<portlet:namespace />fm);

}
</aui:script>


public void editImageInit(ActionRequest actionRequest,
ActionResponse actionResponse) throws Exception {

System.out.println(" ======================ParamUtil.getLong(actionRequest, imageId) "+ParamUtil.getLong(actionRequest, "imageId"));
System.out.println(" ======================ParamUtil.getLong(actionRequest, imageId)" +ParamUtil.getString(actionRequest, "imageId"));
System.out.println("========================actionRequest.getAttribute(imageId) "+actionRequest.getAttribute("imageId"));
System.out.println("========================actionRequest.getParameter(imageId) "+actionRequest.getParameter("imageId"));
}
nghia nguyen
RE: problems to get a checkbox value in action
April 26, 2011 12:05 AM
Answer

nghia nguyen

Rank: New Member

Posts: 15

Join Date: April 24, 2011

Recent Posts

Giuliane Monteiro:
Hi people.

I try to get a value from checkbox in my jsp but it's not work.

I try to get the value this way.

<form
action="<liferay-portlet:actionURL name="editImageInit" />"
enctype="multipart/form-data" method="post"
name="<portlet:namespace />fm"
onSubmit="<portlet:namespace />editImageInit(); return false;">


<p><input name="imageId" type="checkbox" value="<%=igImage.getLargeImageId()%>" /> <img
src="/image/image_gallery?img_id=<%=igImage.getLargeImageId()%>"
width="100" height="100" /></p>


<%
}
}
%> <input type="submit"
value="<liferay-ui:message key="admPopUp.message.editar" />" /></form>

<aui:script>
function <portlet:namespace />editImageInit() {

for(var i=0; i< document.<portlet:namespace />fm.length; i++){

if(document.<portlet:namespace />fm.imageId.checked == true){

document.<portlet:namespace />fm.<portlet:namespace />imageId.value = document.<portlet:namespace />fm.<portlet:namespace />imageId.value;

}
}
submitForm(document.<portlet:namespace />fm);

}
</aui:script>


public void editImageInit(ActionRequest actionRequest,
ActionResponse actionResponse) throws Exception {

System.out.println(" ======================ParamUtil.getLong(actionRequest, imageId) "+ParamUtil.getLong(actionRequest, "imageId"));
System.out.println(" ======================ParamUtil.getLong(actionRequest, imageId)" +ParamUtil.getString(actionRequest, "imageId"));
System.out.println("========================actionRequest.getAttribute(imageId) "+actionRequest.getAttribute("imageId"));
System.out.println("========================actionRequest.getParameter(imageId) "+actionRequest.getParameter("imageId"));
}


Hi I think this code make your checkbox not work
enctype="multipart/form-data"
Tejas patel
RE: problems to get a checkbox value in action
September 7, 2012 6:39 AM
Answer

Tejas patel

Rank: Junior Member

Posts: 71

Join Date: January 23, 2012

Recent Posts

nghia was right in my case also, but what is the solution for that to upload image as well as some data in action url.
if i remove enctype="multipart/form-data" , it gives errors like
"the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/x-www-form-urlencoded".
so what is the best solution for this.
Anindya Mallik
RE: problems to get a checkbox value in action
October 7, 2014 6:54 AM
Answer

Anindya Mallik

Rank: Junior Member

Posts: 29

Join Date: January 15, 2013

Recent Posts

Hi Tejas,

I am facing similar problem. Have you found any solution? Please let me know.
Manali Lalaji
RE: problems to get a checkbox value in action
October 7, 2014 9:21 AM
Answer

Manali Lalaji

Rank: Expert

Posts: 308

Join Date: March 9, 2010

Recent Posts

Hi Anindya,

You need to use UploadRequest in processAction to read values:

1UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
2String checkboxVal= ParamUtil.getString(uploadRequest, "paramName");


HTH!
Anindya Mallik
RE: problems to get a checkbox value in action
October 8, 2014 7:50 AM
Answer

Anindya Mallik

Rank: Junior Member

Posts: 29

Join Date: January 15, 2013

Recent Posts

Hi Manali,

Many many thanks for your reply. That problem get solved, but I am facing another issue.

I have created my check box like this
1<aui:input type="checkbox" name="JobPostingBullHorn" label="BullHorn" />


and getting value from that check box by this way:
1String jobPostingBullHorn = ParamUtil.getString(uploadRequest, "JobPostingBullHorn");


In the server side I am doing some validations, and if the validation failed I am showing error messages to user. Also at that time I have to check whether that check box is checked or not. If it was checked I am checking that check box using jQuery.

From controller I am sending this value to JSP:
1request.setAttribute("jobPostingBullHorn", jobPostingBullHorn);


and in jsp end after getting value I am checking by this code:
 1
 2var jobPostingBullHorn = "<%=renderRequest.getAttribute("jobPostingBullHorn") %>";
 3[b]alert("Job Posting BH from Server: "+jobPostingBullHorn);[/b]
 4if(jobPostingBullHorn != 'null'){
 5        if(jobPostingBullHorn == 'true'){
 6            $('#_SourcingStrategy_WAR_SourcingStrategyportlet_JobPostingBullHornCheckbox').prop('checked', true);
 7            $('#_SourcingStrategy_WAR_SourcingStrategyportlet_JobPostingBullHornCheckbox').val(true);
 8        } else {
 9            $('#_SourcingStrategy_WAR_SourcingStrategyportlet_JobPostingBullHornCheckbox').prop('checked', false);
10            $('#_SourcingStrategy_WAR_SourcingStrategyportlet_JobPostingBullHornCheckbox').val(false);
11        }
12    }


The problem is, if the check box is checked, after validation that alert is showing as true and again checking that check box (by jQuery), but then if I submit the form again then alert is showing false. Don't know the reason.

Please help!!