Re: convert string to object?
Re: convert string to object?
- Subject: Re: convert string to object?
- From: arturo <email@hidden>
- Date: Mon, 01 Dec 2003 13:59:06 -0500
I don't see why all three lists can't be done as I suggested. For me, the bottom line is, given how WO works, why do you
have to convert anything to a string?
Here's an alternative point of view. Let's assume you have an eomodel. Let's futher assume that your model has the following relationships:
Institution <<toMany>> Department <<toMany>> Division
Doing the above you can eliminate your fetch specs in favor of
theInstitution.departments().
theDepartment.divisions().
Then all you're left with is population the initial list of Institution. I would suggest pseudo-code along the lines of
if (loggedInUser.type() == USER.NORMAL)
<<fetch spec limited to reduced list of Institution>>
else if (loggedUser.type() == USER.SUPER)
NSArray instititutions = EOUtilities.objectsForEntityNamed(ec, "Institution");
If at other points you need to reduce the amount of data displayed then you can do something like
reducedData = filteredArrayWithQualifier(theInstitution.departments(), qualifier);
I think that's in NSArray but I don't remember off-hand.
In regards to formatters, they are the Java sanctioned method for turning string identifiers (like division ID) into
an appropriate object. But they don't work with menus, offhand. Personally, I like them. They're easy to write
and work well. I have about a dozen.
But, fundamentally, I don't know why you're turning things into strings. Strings are difficult to work with at best
when you start with an object model. It's like freeze-dried coffee. You had wonderful tasty fresh-brewed coffee to start with.
Then you freeze-dried it and ruined the flavor.
----- Original Message -----
From: Janice M. Cheung
To: arturo
Cc: email@hidden ; email@hidden
Sent: Monday, December 01, 2003 1:17 PM
Subject: Re: convert string to object?
Hi Arturo,
My menu consists of three dropdown lists.
The first list, Institution, is a hard-coded list of Strings to limit the search within
only a few distinct Institutions.
The second list, Department, is an NSArray list of Department names of type Department, converted to strings:
values = (NSDictionary)array.objectAtIndex(i);
obj = values.objectForKey("DEPARTMENT_NAME");
strDeptName=obj.toString();
allDeptName.addObject(strDeptName);
The third list, Division, is an NSArray of Department objects, binding the Department selection to an
instance variable of selectedDivision, as you recommended.
public void fetchDvDepts(){
String qualifier;
qualifier = "institution.institutionLabel = ' " + m_InstSelected + " ' and departmentName = ' " +m_strDvDeptSelected + " ' ";
EOQualifier qual = EOQualifier.qualifierWithQualifierFormat(qualifier, null);
NSMutableArray sort = new NSMutableArray();
EOSortOdering order 1 = new EOSortOrdering("divisionName", EOSortOrdering.CompareAscending);
sort.addObject(order1);
EOFetchSpecification spec = new EOFetchSpecification("Department", qual,sort);
EOEditingContext context = ((Session)session()).defaultEditingContext();
NSArray results = context.objectsWithFetchSpecification(spec);
setM_dvDepts(results);
}
My PDF reports work with the Division dropdown list (sets selectedDivision to selected object from
the array) -- but for SuperUsers the reporting utility has to also work for larger datasets, such as all
Departments (including Divisions) for selectedDepartment, and all Institutions (including all Departments and
Divisions) for selectedInstitution.
Is there any alternative aside from using formatters?
Thanks!
Janice
arturo wrote:
You need to look at how to use formatters. The base class is
java.text.Format.
But in addition to this you're not using the dropdown list in the most
optimal way.
You should be binding the list variable to an NSArray of your objects
(Department
in this case?). You should be binding the display variable to something
that turns
the Department object into a string (toString would work). And you need to
bind
the selection variable to an instance variable of selectedDepartment. Then
the list
will automatically set selectedDepartment to selected object from the array.
If you follow the above approach then you won't need formatters.
----- Original Message -----
From: "Janice M. Cheung" <email@hidden>
Cc: <email@hidden>; <email@hidden>
Sent: Monday, December 01, 2003 12:48 PM
Subject: convert string to object?
Hi there,
Is there a simple function to convert a string to an object?
I am attempting to use something like this for outputting PDFs in
WebObjects, so that
any selections from a dropdown menu (String type) will create those
selected Objects
in a report:
Here is one of my functions to change selected String values into
objects of type Department:
public java.lang.String toObject(){
String currentDept;
currentDept = toObject();
return currentDept;
}
I've also tried to set string types in Search.java and set them in
Session.java to type Department, to
no avail:
--- Search.java
String m_currentDept;
s.setCurrentDepartment(m_currentDept);
(basically I want "currentDept" to be converted to type Department)
--- Session.java
public Department currentDepartment(String currentDept){
return currentDepartment;
}
public Department getCurrentDepartment(String currentDept){
return currentDepartment;
}
public void setCurrentDepartment(Department newCurrentDepartment){
currentDepartment=newCurrentDepartment;
}
These string values are retrieved as qualifiers from the database...
any advice or guidance
would be greatly appreciated!!
Thanks very much!
Happy Happy Holidays!
Janice
_______________________________________________
WebObjects-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
_______________________________________________
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.