Re: Where to set display group bindings i java-file
Re: Where to set display group bindings i java-file
- Subject: Re: Where to set display group bindings i java-file
- From: Jean-François Veillette <email@hidden>
- Date: Fri, 02 Dec 2005 13:15:15 -0500
Hi Micky,
1 ---
I don't mean to be picky, or to argue about the color of the wallpaper,
but I see something here that leave me perplex ...
The code seem to be in a WOComponent subclasss, and in this « display »
layer, you seem to know a lot about the « persistent » layer.
Such code snippets is commonly found on the net as code sample, and I
give it myself as well, but once you get that code and integrate it in
your own code, you shouldn't leave it that way. Such code should be
divided into proper class, depending on responsibilities, etc. The «
display » layer (com.webobjects.appserver.*) shouldn't know and deal
too much with the logic layer. Well, the problem is not much that it's
knowing something about the logic layer, it's more about it know more
about the logic internals than the logic layer itself !
For example,
// in « display / view » layer (WOComponent subclass) :
public WOComponent visEmne() {
emne = subjectItem.subjectText();
NSArray qts =
Quote.quoteWithSubject(session().defaultEditingContext(), subjectItem);
quoteDisplayGroup.setObjectArray(qts);
return null;
}
// in the Quote class, part of the « logic / model / business » layer
public static NSArray quoteWithSubject(EOEditingContext ec, Subject
subj) {
NSArray args = new NSArray(new Object[] { subj });
String qualifierString = "(subject=%@)";
EOQualifier qualifier =
EOQualifier.qualifierWithQualifierFormat(qualifierString, args);
EOFetchSpecification fetchSpec = new EOFetchSpecification("Quote",
qualifier, null);
return ec.objectsWithFetchSpecification(fetchSpec);
}
This hide the internals of the relation between a quote and a subject.
This will gradually beef up your « logic » layer to a point where you
could rewrite the same app, using a different gui framework (think
console based tools, web-service front-end or rich java-client), and
use a rich model to drive it.
As you can see, I've also changed the qualifier string, to test against
the subject object, not the subject string it contain. This allow EOF
to do a primary key join instead of a search on a text column that you
might not want to index.
2 ---
If you are building a search page with a form to qualify against some
attributes, you get values in instance variables, and then user push
'search' to see the results.
For such situation, instead of binding the form element to instance
variable, you could bind it directly to the displaygroup.queryMatch
attributes.
For the above example, you could use a WOToOneRelationship component to
qualify on the quote.subject relationship. I do not have sample code
to give you, but I'm pretty sure there is a lot somewhere on the web
(or maybe right on your disk as part of the wo example code).
3 ---
there is not point 3 ;-)
- jfv
Le 05-12-02, à 10:49, Micky Holdorf a écrit :
On 01/12/2005, at 18.15, Jean-François Veillette wrote:
I have a display group quoteDisplayGroup in a webcomponent.
The question is where in the components Java file I set the binding:
quoteDisplayGroup.queryBindings().takeValueForKey(value,
"attributeValue");
and how...
Another question... in my research I have come upon this one:
quoteDisplayGroup.queryBindings().setObjectForKey(value,
"attributeValue");
Which one should I use?
think of queryBindings() as a NSMutableDictionary ( NSKeyValueCoding
), thus you can use both interfaces.
you can do it almost anywhere you want ( as far as it make sense ;-)
).
- jfv
Hi there...
I never got it to work but I found another way to show the data from
the database. I use this code instead. It generates a qualifier and
fetch specification programmiticaly and populate my displaygroup with
the fetched data.
public WOComponent visEmne() {
emne = subjectItem.subjectText();
NSArray args = new NSArray(new Object[] { emne });
String qualifierString = "(subject.subjectText=%s)";
EOQualifier qualifier =
EOQualifier.qualifierWithQualifierFormat(qualifierString, args);
EOFetchSpecification fetchSpec = new EOFetchSpecification("Quote",
qualifier, null);
EOEditingContext ec = session().defaultEditingContext();
NSArray tempResultsArray =
ec.objectsWithFetchSpecification(fetchSpec);
quoteDisplayGroup.setObjectArray(tempResultsArray);
return null;
}
/Micky Holdorf
http://www.freeiPods.com/?r=21419063
_______________________________________________
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