Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 1. Lets start off by getting a delegator and using it to list all the Person entities - we will store the result in a variable.  The code should be pretty self evident, it is simply beanshell, using familiar OFBiz API classes.  The interesting bit is in the screen, where we use the special forEach attribute to iterate all the Persons and make a dropdown list from them.  We can access fields on the GenericValues each iterator variable (in ZK it is always called each) with the Expression Language DOT notation.   And finally, see how we use the value attribute of each listitem, to hold a reference to the Person - not its PK but the GenericValue object itself.  This will come in handy in the next step.

Code Block

 <?page title="Incredible Browser"?>

<window title="Incredible Window">
 <zscript>
  import org.ofbiz.entity.GenericDelegator;

  delegator = GenericDelegator.getGenericDelegator("default");
  persons = delegator.findAll("Person");
 </zscript>
  <listbox mold="select">  <!-- mold: select means a dropdown list -->
   <listitem forEach="${persons}" label="${each.firstName} ${each.lastName}" value="${each}"/>
  </listbox>
</window>

2. Now that we can list our people, we need to have a screen for editing them.  The next code sample expands upon the first by creating a little edit form but keeping it hidden until the user actually selects a person for editing.  Note how we take advantage of the selected listitem's value payload - a Person entity.

3. Finally, lets add a Save button and make it do something.  Note how we dynamically update the person's name on the list, too.  All ZK UI components can be dynamically manipulated via beanshell or Java in this way.

Part 3: Integration with OFBiz backend - via Spring

...