Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-2853

ZK8 Handles selectedItem that is a complex object differently than ZK7

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Normal Normal
    • None
    • 8.0.0
    • Databind

      Often times when editing an object you want to allow the user to select from a dropdown list a property that you want to set on the object. Often times this object you are selecting to set represents a complex object (pojo) vs a simple java data type.

      For example you're editing an Employee and you then need to select a Department from a drop down list.

      I have two issues. One is a BUG in 8.0 compared to 7.0.3 and the other is a MAJOR suggestion.

      First the bug:
      In 7.0.3 as long as I have an equals method on my nested object, selectedItem in my listbox will have the appropriate item selected. However this is currently NOT working 8.0. For example here is sample code:

      <row>
      	<cell sclass="row-title">Department:</cell>
      	<cell>
      		 <listbox model="@load(vm.departments)" selectedItem="@bind(emp.department)"
      				 width="200px" mold="select" rows="1"
      				 id="departmentsList">
      				<template name="model" var="item">
      					<listitem>
      						<listcell label="@load(item.name)"/>
      					</listitem>
      				</template>
      		</listbox>
      	</cell>
      </row> 
      

      In the above Employee has a Department set on it and the equals method on Department is set to evaluate equals on the departmentId. However, in the above code in ZK8, the department list item is NOT selected, yet with the same code it IS selected properly in .7.0.3
      If you'd like to see the above in action just build from this project I created on github
      https://github.com/rickcr/mybatis-spring-zk-multimodule

      For my suggestion... I find it EXTREMELY frustrating that I'm forced to create an equals method on the POJO that might only really be appropriate for ZK. For example many times I'll want to retrieve an Employee with a Department but I only care about the department ID being set on the Department object inside of Employee. If I were to then base the Department object equals method on all the Department properties there would be no way for selectedItem to work! This is very frustrating. A LONG time ago I suggested in the forums that you should have something that existed over 12 years ago in Struts1.0 - just allow a property on the listbox called "selectedItemEqualsProperty" and in this way the user could provide what property they want to base equality on for marking the listbox item selected. This feature would be a HUGE improvement.

      As it stands now without this feature, a user must either override equals (which isn't always easy if using a shared POJO library) or else do nasty iterations inside of your View Model (looping over the objects and testing if a particular property matches the one from your selected item.)

            cor3000 cor3000
            rickcr rickcr
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: