|
|
Sacha Mallais
|
|||||||||||
|
|
|
|
|||||||||
| Navigate Database Table: "WOFAQ" | ||||||||||
| Current record is #17 out of 21 in found set (21 total records in table) | ||||||||||
|
|
|||||||||
| Question | How should I work with boolean values? |
|---|---|
| Answer |
Store string literals in your database, use java.lang.Booleans in your classes, and instruct EOF to map between these two datatypes. Use WOCheckbox or WORadioButton components to provide values from the user to EOF. No extra coding is required. In EOM, add an attribute to your entity that uses a char or varchar External Type and customize the Internal Data Type using java.lang.Boolean as follows [see fig. 1]. Now we can store the string literals 'true' and 'false' in the DB to represent our booleans there, use Java Booleans in our Java class, and allow EOF to map between the two on our behalf. Once you have published your new Java class and respective DB table with EOM, you can use a WOCheckbox or WORadioButton in WOB to provide a boolean from the front-end to EOF. For this, bind your entity's boolean attribute to the 'checked' attribute of WOCheckBox [see fig. 2] Assuming you have a WOForm with a WOSubmit button bound to a method that saves form data to the database, you need only bind your entity's Boolean attribute to the WOCheckBox [above] and everything will Just Work. A description of this approach and references to others can be found in Practical WebObjects, Hill & Mallais 2004, p42. |
| Figure 1 | Filename: boolean_attribute.jpg (MIME Type: image/jpeg; Size: 30.0 Kb) |
| Figure 2 | No file available. |
| Figure 3 | No file available. |
| Date Modified | May 10 2005 |
| Modified By | lachlans@oreti.co.nz |