Foros de discusión

search-container filled with HashMap

Alex Garland, modificado hace 8 años.

search-container filled with HashMap

New Member Mensajes: 14 Fecha de incorporación: 14/01/16 Mensajes recientes
Hi,
i want to create a table and fill it with values from a HashMap. its a simple table and my Code looks like the following:


<%
Map<string, string> entry1 = new HashMap<string, string>()
entry1.put("name", "example 1")
entry1.put("description", "example description 1")

Map<string, string> entry2 = new HashMap<string, string>()
entry2.put("name", "example 2")
entry2.put("description", "example description 2")

ArrayList list = new Arraylist();
list.add(entry1);
list.add(entry2);
%&gt;



<liferay-ui:search-container delta="10" emptyresultsmessage="no-entries">
	<liferay-ui:search-container-results results="<%= list %>" total="<%= list.size() %>" />

	<liferay-ui:search-container-row classname="java.util.HashMap" keyproperty="name" modelvar="transfer_target">
		<liferay-ui:search-container-column-text name="name" value="<%= transfer_target.get(" name") %>"
		/&gt;

		<liferay-ui:search-container-column-text name="description" value="<%= transfer_target.get(" description") %>"
		/&gt;
	</liferay-ui:search-container-column-text></liferay-ui:search-container-column-text></liferay-ui:search-container-row>

	<liferay-ui:search-iterator />

</liferay-ui:search-container></string,></string,></string,></string,>


but it does not work this way. how do i put the values correctly in the table?
thumbnail
Devang Patel, modificado hace 8 años.

RE: search-container filled with HashMap

Regular Member Mensajes: 247 Fecha de incorporación: 19/01/15 Mensajes recientes
Hi Alex Garland,

Syntax : ${MapName[modelVar.map_key].value}
Try this : ${entry1[transfer_target.key]}
Refer Link
HTH.

Regards,
Devang Patel
thumbnail
Sandeep Nair, modificado hace 8 años.

RE: search-container filled with HashMap (Respuesta)

Liferay Legend Mensajes: 1744 Fecha de incorporación: 6/11/08 Mensajes recientes
Possible reasons of error

->Make sure you have imported liferay-ui taglib
->I hope the code is proper and no errors. I see that there is no semi colon after map and list declaration and initialization.
->Either escape or use single quotes when you are getting the value from map.
->Try to use toString after getting the value.

I have refactored your code so as to incorporate the comments I wrote above, but havent tested. See if it is working for you

&lt;%@page import="java.util.ArrayList"%&gt;
&lt;%@page import="java.util.HashMap"%&gt;
&lt;%@page import="java.util.Map"%&gt;

&lt;%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %&gt;
&lt;%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %&gt;

<portlet:defineobjects />

This is the <b>Playground</b> portlet.

&lt;%
 Map<string, string> entry1 = new HashMap<string, string>();
 entry1.put("name", "example 1");
 entry1.put("description", "example description 1");
 
 Map<string, string> entry2 = new HashMap<string, string>();
 entry2.put("name", "example 2");
 entry2.put("description", "example description 2");

ArrayList list = new ArrayList();
list.add(entry1);
list.add(entry2);
%&gt;

<liferay-ui:search-container delta="10" emptyresultsmessage="no-entries">
    <liferay-ui:search-container-results results="<%= list %>" total="<%= list.size() %>" />
    <liferay-ui:search-container-row classname="java.util.HashMap" keyproperty="name" modelvar="transfer_target">
        <liferay-ui:search-container-column-text name="name" value="<%= transfer_target.get(&quot;name&quot;).toString() %>" />

        <liferay-ui:search-container-column-text name="description" value="<%= transfer_target.get(&quot;description&quot;).toString() %>" />
    </liferay-ui:search-container-row>

    <liferay-ui:search-iterator />

</liferay-ui:search-container></string,></string,></string,></string,>
Alex Garland, modificado hace 8 años.

RE: search-container filled with HashMap

New Member Mensajes: 14 Fecha de incorporación: 14/01/16 Mensajes recientes
Thank you.

This worked exactly as I wanted it to.