Re: WODisplayGroup help
Re: WODisplayGroup help
- Subject: Re: WODisplayGroup help
- From: Robert Walker <email@hidden>
- Date: Mon, 3 Nov 2003 21:56:22 -0500
David,
First of all, I'm not sure why you're using a WODisplayGroup if you're
having it fetch just one object. WODisplayGroups are typically use to
fetch a list of objects based on some qualifier and allow you to
control both the qualification and display of the fetched objects.
If you want to fetch just one object that matches a value you can use
something like:
EOEnterpriseObject myObject = EOUtilities.objectMatchingKeyAndValue(ec,
"MyEntity", "myKey", myValue); (Look up this method in
com.webobject.eoaccess.EOUtilities for correct syntax and usage)
Then you can just bind your form values to the attributes of myObject.
Now, if you do want to fetch a list of objects then a WODisplayGroup
would be appropriate. But a WODisplayGroup is not sufficient on it's
own. You use it in combination with a WORepetition. You typically
bind the WODisplayGroup.displayedObjects() to the WORepetition's List
binding. Then bind the WORepetition's Item binding to an instance of
your EOEnterpriseObject class.
1. Add and configure your WODisplayGroup.
2. Add a new key using WOBuilder as an instance variable of the type
of your EOEntity. Name it something like currentObject, currentPerson,
or whatever makes sense.
3. Add a WORepetition to your page. (This repetition often wraps the
second row of a table.)
3. Bind the WODisplayGroup.displayedObjects() to the repetition's List.
4. Bind currentObject to the repetition's Item.
5. Create your Form and bind the form fields to the attributes of
currentObject.
This is in case you're creating an editable list. If you want a list
with a separate edit form so the user can select a row from the list
and use the edit form to edit the values of the selected row then add a
button or hyperlink to each row, bind it to a "select" action to set
the display group's selectedObject.
Like this:
public WOComponent selectAction() {
myObjectDisplayGroup.selectObject(currentObject);
}
In this case you will bind your edit form's input fields to
myObjectDisplayGroup.selectedObject()'s attributes.
It is also possible to use separate pages to query, list, and edit
objects as is the case when using direct-to-web applications.
Hope this helps, and is not to confusing. This is a difficult concept
to explain in an email. I would suggest perusing some of the example
applications in /Developer/Examples/JavaWebObjects. There are many
examples of using display groups in these applications.
On Nov 3, 2003, at 6:10 PM, David Griffith wrote:
Hi all,
I don9t really understand the operation of WODisplayGroups and how to
use
them.
What I am trying to do:
When a given page loads (a component initialises) it searches for a
record
in a table based on a value that is already in a variable. This is
achieved
with a WODisplayGroup and a pre defined model with a fetch spec. This
part
appears to work. I get a displayedObjects>0 for the DisplayGroup.
Now, the
user never clicks anything on this page to select9 an object in the
DisplayGroup so I need to have access to the row in the DisplayGroup
that I
need, namely the first one as there should only be one.
I want to be able to modify these values via a form on this page, then
write
the new values to the database. Also, I want to be able to insert new
rows
if there was no existing row located (from above). In other words, if
no
row was found in the database, give me some empty fields to type in,
then
when I save, insert instead of update.
The problems I have:
1. The form fields do not display any values - currently using
imageDisplayGroup.selectedObject.imagesImageId for example. I guess
this is
because selected object is null, but don9t know what to do next.
2. I don9t know how to set a new record for the user to enter data in,
then
be able to add some values myself before the insert and have it insert
instead of update. Even if I could see the values in the form, how
would I
assign some other values programatically? If I cast the selected
object to
Images9 and modify the values, does this then have to be put back9
in the
DisplayGroup or does it update the values in the DisplayGroup by
reference?
Any helpful hints would be appreciated ;-)
Thanks,
Dave.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
--
Think Different
Robert Walker
www.robertwalker1.com
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.