0

accessing a map value by key in a variable

asked 2009-07-05 11:09:39 +0800

fedd gravatar image fedd
6

updated 2009-07-05 11:10:27 +0800

Hi,

it seems that @ expressions parse only dots (.) when accessing the maps; when i try to take the key from a variable putting it in a square brackets, it considers the whole as one var name.

i am trying to do the following example of working with data bound and live list:

<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./mywin"?>
<window id="mywin" border="none">
ZK name check list :
	<zscript>
  // prepare persons of one type
  Set persons = new HashSet();
	HashMap person1 = new HashMap();
	person1.put("firstName", "mary");
	person1.put("lastName", "bearss");
	persons.add(person1);
	HashMap person2 = new HashMap();
	person2.put("firstName", "ann");
	person2.put("lastName", "moe");
	persons.add(person2);
	HashMap person3 = new HashMap();
	person3.put("firstName", "arnold");
	person3.put("lastName", "schwartz");
	persons.add(person3);
	HashMap person4 = new HashMap();
	person4.put("firstName", "pete");
	person4.put("lastName", "boyle");
	persons.add(person4);

  //make a map of persons of several types
  Map personTypes = new HashMap();
  personTypes.put("teachers", persons);

  String type = "teachers";

  </zscript>

	<listbox model="@{personTypes.teachers}" selectedItem="@{selected}" rows="4">
		<listhead >
				<listheader label="First Name"/>
				<listheader label="Last Name"/>
		</listhead>
		<listitem self="@{each=person}">
      <listcell label="@{person.firstName}" />
      <listcell label="@{person.lastName}" />
    </listitem>
	</listbox>
	<grid>
		<columns>
			<column label="First Name" />
			<column label="Last Name" />
		</columns>
		<rows>
			<row>
				<textbox value="@{selected.firstName}" />
				<textbox value="@{selected.lastName}" />
			</row>
		</rows>
	</grid>
</window>

this works fine until i try to use the type variable:

<listbox model="@{personTypes [ type ] }" selectedItem="@{selected}" rows="4">

then it shows nothing.

please help - what do i do wrong or is it a bug?

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2009-07-06 08:35:27 +0800

fedd gravatar image fedd
6

should i post it as a bug?

link publish delete flag offensive edit

answered 2009-07-09 10:53:22 +0800

robbiecheng gravatar image robbiecheng
1144 2
http://robbiecheng.sys-co...

plis remove "[ type ]", we don't support it.

/robbie

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-07-05 11:09:39 +0800

Seen: 180 times

Last updated: Jul 09 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More