Foros de discusión

How to get the KeyValuePair in the portlet class?

Suyesh Amatya, modificado hace 9 años.

How to get the KeyValuePair in the portlet class?

Junior Member Mensajes: 61 Fecha de incorporación: 22/08/14 Mensajes recientes
In my form I have KeyValuePair as

List<keyvaluepair> left = new ArrayList<keyvaluepair>(), right = new ArrayList<keyvaluepair>();
	left.add(new KeyValuePair("1key", "item1value"));
	left.add(new KeyValuePair("1key", "item4value"));
	left.add(new KeyValuePair("1key", "item3value"));
	right.add(new KeyValuePair("1key", "item2value"));

<liferay-ui:input-move-boxes leftBoxName="availabletors" leftTitle="Type of Repository Available" leftList="<%=left %>" rightBoxName="selectedtors" rightTitle="Type of Repository Selected" rightList="<%=right %>" /></keyvaluepair></keyvaluepair></keyvaluepair>


In the portlet class, I am getting it as
String[] right= ParamUtil.getParameterValues(actionRequest, "selectedtors");
System.out.println(right.length);
for(String str : right){
System.out.println(str);
}

But this only gives me the keys of KeyValuePair like "1key". I want to retrieve the corresponding values as well like "item1value", "item2value", ....How do I get the values in the Portlet class?
thumbnail
Mayur Patel, modificado hace 9 años.

RE: How to get the KeyValuePair in the portlet class?

Expert Mensajes: 358 Fecha de incorporación: 17/11/10 Mensajes recientes
Hi Suyesh,

You can use alloyui module to store selected items inside hiddenFields and you can retrieve from hiddenFields in your action class.

Refer this blog

Thanks.
Suyesh Amatya, modificado hace 9 años.

RE: How to get the KeyValuePair in the portlet class?

Junior Member Mensajes: 61 Fecha de incorporación: 22/08/14 Mensajes recientes
Hi Mayur,

But I am only getting the keys, I need values as well.
thumbnail
Mayur Patel, modificado hace 9 años.

RE: How to get the KeyValuePair in the portlet class?

Expert Mensajes: 358 Fecha de incorporación: 17/11/10 Mensajes recientes
Can you check below code and see what you are getting?

ParamUtil.getParameter(actionRequest, "selectedtors");
Suyesh Amatya, modificado hace 9 años.

RE: How to get the KeyValuePair in the portlet class?

Junior Member Mensajes: 61 Fecha de incorporación: 22/08/14 Mensajes recientes
String[] left = ParamUtil.getParameterValues(actionRequest, "selectedtors");


// System.out.println(left.length);
for(String str : left){
System.out.println(str);
}

This just prints out the keys defined in the KeyValurPair like 1key. I want to be able to retrieve the corresponding value associated with this key. i.e. item1value. I mean the values displayed inside the box itself.
siddhant jain, modificado hace 9 años.

RE: How to get the KeyValuePair in the portlet class?

Junior Member Mensajes: 69 Fecha de incorporación: 19/03/13 Mensajes recientes
Hi Suyesh,
are you sure that your code:
Suyesh Amatya:


In the portlet class, I am getting it as
String[] right= ParamUtil.getParameterValues(actionRequest, "selectedtors");
System.out.println(right.length);
for(String str : right){
System.out.println(str);
}


is working??
because ParamUtil class dosen't have getParameterValues(ActionRequest, String) method and it is extending Object class directly so nither of its parent class does have that method so how are you getting this code working??

Regards
Siddhant
Suyesh Amatya, modificado hace 9 años.

RE: How to get the KeyValuePair in the portlet class?

Junior Member Mensajes: 61 Fecha de incorporación: 22/08/14 Mensajes recientes
It does have ParamUtil.getParameterValues(HttpServletRequest request, String param) and I am using it. I get the values of the key of
left.add(new KeyValuePair("1key", "item1value"));
i.e. I am getting 1key printed however I cannot get the value "item1Value"
Suyesh Amatya, modificado hace 9 años.

RE: How to get the KeyValuePair in the portlet class? (Respuesta)

Junior Member Mensajes: 61 Fecha de incorporación: 22/08/14 Mensajes recientes
Seems like there is no such utility method to get the values instead. So I will resort to retrieve the values in the portlet class by making the value as part of the key. That means I will define my key as
new KeyValuePair("key_val", "val") , then I can split the string to get the desired value.