掲示板

search-container filled with HashMap

8年前 に Alex Garland によって更新されました。

search-container filled with HashMap

New Member 投稿: 14 参加年月日: 16/01/14 最新の投稿
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
8年前 に Devang Patel によって更新されました。

RE: search-container filled with HashMap

Regular Member 投稿: 247 参加年月日: 15/01/19 最新の投稿
Hi Alex Garland,

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

Regards,
Devang Patel
thumbnail
8年前 に Sandeep Nair によって更新されました。

RE: search-container filled with HashMap (回答)

Liferay Legend 投稿: 1744 参加年月日: 08/11/06 最新の投稿
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,>
8年前 に Alex Garland によって更新されました。

RE: search-container filled with HashMap

New Member 投稿: 14 参加年月日: 16/01/14 最新の投稿
Thank you.

This worked exactly as I wanted it to.