Re: Set String methods for Flattened Relationship Attributes
Re: Set String methods for Flattened Relationship Attributes
- Subject: Re: Set String methods for Flattened Relationship Attributes
- From: Lachlan Deck <email@hidden>
- Date: Fri, 21 Oct 2005 05:28:54 +1000
Hi Janice,
On 21/10/2005, at 1:59 AM, Janice Cheung wrote:
Hi David!
Thanks for your input. I really appreciate your advice!
Yes, I am trying to take arrays of objects and reduce their values
to comma separated strings. This is for a client request to
provide an editable text field where values of objects (email
contacts, specifically) are displayed for an end user to add new e-
mail addresses (Strings) to send out broadcast messages.
I have something like this on an Email Contacts HTML page (four
editable text fields):
* From: (session.currentUser WOTextField)
* To: (server.getEmailContacts WOTextField)
* Subject: (subject WOTextField)
* Body: (htmlMsg WOTextField)
I am NOT trying to save the server.getEmailContacts text field to
the database in this EmailContacts HTML page. I am merely trying
to provide the end user with the functionality to append any
additional strings/email addresses to the server.getEmailContacts
WOTextField.
For example, in my To: field, I will have something like
To: "email@hidden, email@hidden" (server.getEmailContacts WOTextField)
Now, an endUser will mosey along and say, 'Why, I'd like to add
email@hidden to the e-mail contacts values'.
I'd hazzard a guess that an end user would appreciate something more
akin to:
<form>
<table cellpadding=5 border=0 cellspacing=0>
<tr>
<th>Recipient</th>
<th>To</th>
<th>CC</th>
<th>None</th>
</tr>
<webobject name=RecipientsRepetition>
<tr>
<td><webobject name=ARecipient_NAMEString></
webobject></td>
<td><webobject name=ARecipient_TORadioButton></
webobject></td>
<td><webobject name=ARecipient_CCRadioButton></
webobject></td>
<td><webobject name=ARecipient_NONERadioButton></
webobject></td>
</tr>
</webobject>
<caption align=TOP>Select your recipients below...</caption>
</table>
<...>
</form>
----------------------
ARecipient_NAMEString: WOString {
value = aRecipient.name;
}
ARecipient_CCRadioButton: WORadioButton {
name = aRecipient.name;
selection = aRecipientFieldType;
value = "CC";
}
ARecipient_NONERadioButton: WORadioButton {
name = aRecipient.name;
selection = aRecipientFieldType;
value = "NONE";
}
ARecipient_TORadioButton: WORadioButton {
name = aRecipient.name;
selection = aRecipientFieldType;
value = "TO";
}
RecipientsRepetition: WORepetition {
item = aRecipient;
list = emailRecipients.allKeys;
}
----------------------
// keys: recipientObjects
// values: ["NONE" || "TO" || "CC"]
protected NSMutableDictionary emailRecipients;
protected EmailRecipient aRecipient; // iterator for WORepetition
protected String additionalTOContacts;
protected String additionalCCContacts;
protected String messageSubject;
protected String messageBody;
public MyComponent(WOContext context) {
super(context);
additionalTOContacts = additionalCCContacts = messageSubject =
messageBody = null;
}
public NSMutableDictionary emailRecipients() {
if ( emailRecipients == null ) {
NSMutableArray recipients; // gather via fetch spec or
something
NSMutableArray fieldTypes; // put default field types per
recipient
emailRecipients = new NSMutableDictionary( fieldTypes,
recipients );
}
return emailRecipients;
}
public String aRecipientFieldType() {
return ( String )emailRecipients.valueForKey( aRecipient );
}
public void setARecipientFieldType( String value ) {
emailRecipients.takeValueForKey( value, aRecipient );
}
<...>
If you are receiving an array of objects and you need to display
their values separated by commas then use a WORepetition and have
it build the presentation for you. That's what it's there for
(and you write no code).
Yes! I am using a WORepetition already to display values of objects
that are NOT separated by commas. To clarify, there is no need for
any comma separated strings of my values to go back to my database
again. The comma separated strings are only used for the
EmailContacts HTML page. I have a ViewServerDetail HTML page that
contains two WORepetitions, with various string values of objects
pulled from the database. Instead of something like
server.getEmailContacts(), I have two WORepetitions with the
following bindings:
Repetition1: WORepetition {
item = m_ServerContract;
list = server.serverContracts;
}
TextField1: WOTextField {
value = m_serverContract.contact.fullName;
}
TextField2: WOTextField {
value = m_serverContract.contact.email;
}
Hypothetically, the values within these WOTextFields should also
save properly with saveChanges() to the database. However, changes
to these text fields are not being updated, but only for one of the
two WORepetitions (which are identical aside from the fact that one
is filtered by Conditionals for billing Contacts, while the other
is filtered by Conditionals for administrative contacts).
Specifically, Billing Contact edits are being saved, but
AdministrativeContacts are not, although they are using the same
WORepetition and textField values.
In addition, other TextFields (which also do not contain any comma
separated values) that return object values are not saving to the
database. These are also based on flattened relationships.
More specifically, I have something like this:
public String serial() {
String regex = "(,?\\Q<com.webobjects.foundation.NSKeyValueCoding
$Null>\\E)+";
NSArray serialNumbers = (NSArray)((NSArray)storedValueForKey
("toDevice")).valueForKey("serialNum");
return NSArray.componentsJoinedByString(",").replaceAll( regex,
"" );
}
and in my binding, I have:
TextField3: WOTextField {
value = server.getSerial; /*
--------------------------------THIS WON'T SAVE :
( ------------------------------------*/
/* Because the above is wrong. [1] */
value = server.serial; // is correct as it allows WebObjects to
find the getter AND the setter method.
}
[1] See the NSKeyValueCoding interface > valueForKey definition for
details.
As mentioned before... these are classes you should familiarise
yourself with. They're very handy.
However, if I re-write TextField3 in the following manner the value
will save correctly:
TextField3: WOTextField{
value = server.toDevice.serialNum /*
-------------------------------- THIS WILL SAVE!
------------------------------------*/
}
Because it follows the above principles...
Am I missing something trivial? Am I overlooking things and
barraging too much messy code on my project?
Implied answers there perhaps ;-)
I am sorry I am baffling people with my wayward means of
implementation... but I really appreciate any help and advice.
Thank you very much for your time and attention to this important
matter.
The Key[ValueCoding] thing you are missing, it would seem, is a good
grasp of the MVC methodologies employed in the WebObjects
environment. i.e., it sounds like you're fighting against the OO
nature of WO (where all the benefits are awaiting) and wanting to
treat the data encapsulated by the various objects in the system as a
combined plain text file that you might parse from something like a
shell script. Better put, you're thinking about the tables and
columns in your database and you need to instead think about objects
and messages that those objects respond to. To borrow a phrase: EOF
will do the rest...
Oh, and, of course, there's a few pieces in the puzzle that you
obviously weren't aware of regarding the glue between the html
template and your object code (i.e., the wod file stuff).
with regards,
--
Lachlan Deck
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden