Foren
How to get values of checkboxes iin action class?
Shahbaj Maner, geändert vor 10 Jahren.
How to get values of checkboxes iin action class?
New Member Beiträge: 11 Beitrittsdatum: 29.11.13 Neueste Beiträge
Hello,
I am using checkboxes for hobbies..But i am getting null in action class. please help me how to get that values in action class?
This my .jsp page code
This my action class where I want that values
Both of these are returning no values...Please help me...
Thanks in advance
I am using checkboxes for hobbies..But i am getting null in action class. please help me how to get that values in action class?
This my .jsp page code
<input type="checkbox" name="hobbies" value="1"> Art
<input type="checkbox" name="hobbies" value="2"> Music
<input type="checkbox" name="hobbies" value="3"> Sports
<input type="checkbox" name="hobbies" value="4"> Trekking
This my action class where I want that values
public void test (ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
String[] hobbiesList =ParamUtil.getParameterValues(actionRequest,"hobbies");
String[] hobibiesList1 = actionRequest.getParameterValues("hobbies");
}
Both of these are returning no values...Please help me...
Thanks in advance
Mika Koivisto, geändert vor 10 Jahren.
RE: How to get values of checkboxes iin action class?
Liferay Legend Beiträge: 1519 Beitrittsdatum: 07.08.06 Neueste Beiträge
Per portlet spec you need to namespace your parameter name. Liferay 6.2 now enforces that although there's a setting to turn the old behavior on but I can't remember what it was off the top of my head and it's better to namespace them always.
Mika Koivisto, geändert vor 10 Jahren.
RE: How to get values of checkboxes iin action class? (Antwort)
Liferay Legend Beiträge: 1519 Beitrittsdatum: 07.08.06 Neueste Beiträge
It's all documented in the developer guide's section 3 - Passing information from action phase to render phase. The details are under using portlet namespacing.
For the lazy: This is what you put on your portlet's liferay-portlet.xml to allow non namespaced parameters:
For the lazy: This is what you put on your portlet's liferay-portlet.xml to allow non namespaced parameters:
<requires-namespaced-parameters>false</requires-namespaced-parameters>
Javier Vera, geändert vor 9 Jahren.
RE: How to get values of checkboxes iin action class?
New Member Beiträge: 18 Beitrittsdatum: 01.08.14 Neueste Beiträge
hey man why would you teach the lazy way?
i'm having the same issue right now with a biggie portlet....
and i do need these namespace parameters.
if you could share a quick thing on how to achieve the real goal...
the guy up there had tried :
String[] hobbiesList =ParamUtil.getParameterValues(actionRequest,"hobbies");
String[] hobibiesList1 = actionRequest.getParameterValues("hobbies");
and then he got an empty array as result.
i myself am facing this too.
So, i'd like, if you could, you to guide us with the scenario.. or maybe we need to handle this actionRequest in a different way?
anyway, any advice would always be greatly taken.
peace!
i'm having the same issue right now with a biggie portlet....
and i do need these namespace parameters.
if you could share a quick thing on how to achieve the real goal...
the guy up there had tried :
String[] hobbiesList =ParamUtil.getParameterValues(actionRequest,"hobbies");
String[] hobibiesList1 = actionRequest.getParameterValues("hobbies");
and then he got an empty array as result.
i myself am facing this too.
So, i'd like, if you could, you to guide us with the scenario.. or maybe we need to handle this actionRequest in a different way?
anyway, any advice would always be greatly taken.
peace!
Tanweer Ahmed ., geändert vor 1 Jahr.
RE: How to get values of checkboxes iin action class?
Expert Beiträge: 322 Beitrittsdatum: 11.03.10 Neueste Beiträge
Hi Javier,
If you really need the namespaced parameters, use the following for all the html elements
i. with aui html fields e.g. <aui:input name="test" /> OR
ii with normal html fields e.g. <input type="text" name="<portlet:namespace/>test">
Also make sure your Portlet Class is registered in portlet.xml within the <portlet-class>(I did this mistake earlier).
-Tanweer
If you really need the namespaced parameters, use the following for all the html elements
i. with aui html fields e.g. <aui:input name="test" /> OR
ii with normal html fields e.g. <input type="text" name="<portlet:namespace/>test">
Also make sure your Portlet Class is registered in portlet.xml within the <portlet-class>(I did this mistake earlier).
<portlet-class>com.xyz.test.TestPortlet</portlet-class>
-Tanweer
Javier Vera, geändert vor 9 Jahren.
RE: How to get values of checkboxes iin action class?
New Member Beiträge: 18 Beitrittsdatum: 01.08.14 Neueste Beiträge
hi ho, Tanweer.
Thanks for the quick reply.
So far i've tryed these without success.
and
note these two have the "name" property set and both are "aui" components.
However, on the action class i get to the method ( i put the portlet-class correctly ), i find empty parameters.
i try to catch these with the following:
String[] arrString = ParamUtil.getParameterValues(actionRequest, "caseapp");
String arrTry = ParamUtil.getString(actionRequest, "caseapp");
String[] arrString2 = ParamUtil.getParameterValues(actionRequest, "caseapp");
yet the result is the same, i know i am doing something wrong i just figure out what.
any idea besides taking namespace of parameters????
Thanks for the quick reply.
So far i've tryed these without success.
<aui:input type="checkbox" class="case" name="caseapp[]" value="<%= String.valueOf(sContent.getPrimaryKey()) %>" />
and
<aui:input type="checkbox" class="case" name="caseapp" value="<%= String.valueOf(sContent.getPrimaryKey()) %>" />
note these two have the "name" property set and both are "aui" components.
However, on the action class i get to the method ( i put the portlet-class correctly ), i find empty parameters.
i try to catch these with the following:
String[] arrString = ParamUtil.getParameterValues(actionRequest, "caseapp");
String arrTry = ParamUtil.getString(actionRequest, "caseapp");
String[] arrString2 = ParamUtil.getParameterValues(actionRequest, "caseapp");
yet the result is the same, i know i am doing something wrong i just figure out what.
any idea besides taking namespace of parameters????
Tanweer Ahmed ., geändert vor 1 Jahr.
RE: How to get values of checkboxes iin action class?
Expert Beiträge: 322 Beitrittsdatum: 11.03.10 Neueste Beiträge
Hi Javier,
As a test I did below and it works as expected.I hope your form uses post method.
-Tanweer
As a test I did below and it works as expected.I hope your form uses post method.
<form method="post" id="fm" name="fm" action="<portlet:actionURL />">
<aui:input type="checkbox" name="caseapp" value="123" />
<aui:button type="submit" value="Save" />
</form>
final String caseapp = ParamUtil.getString(actionRequest, "caseapp");
System.out.println(caseapp);
-Tanweer
Javier Vera, geändert vor 9 Jahren.
RE: How to get values of checkboxes iin action class?
New Member Beiträge: 18 Beitrittsdatum: 01.08.14 Neueste Beiträge
Yup, just to clarify this is what i used.
then i just catch the "resulttxt" in the action method.
thank you for the time
and to the bottom i added<aui:form name="frm" method="POST" action="<%= oUrl.toString() %>"> </aui:form>
<!-- daaa daaa --> <div id="panel"> <section> <div> <input type="checkbox" class="Checkbox" name="caseapp" value="<%= String.valueOf(sIndicador.getPrimaryKey()) %>" title="" <%="(isAlreadyRegistered(iCut).size()"> 0)?"Checked":"" %> /> </div> <%} %> </section> </div> [b]<aui:input id="resulttxt" type="hidden" name="resulttxt" />[/b] <aui:button onclick="collectChk();" id="clickmepri" value="Grabar" type="submit"></aui:button>
$('#<portlet:namespace />resulttxt').val($('.Checkbox:checked').map(function() {
return this.value;
}).get().join(', '));
}
then i just catch the "resulttxt" in the action method.
thank you for the time