• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Design Question...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Design Question...


  • Subject: Re: Design Question...
  • From: LD <email@hidden>
  • Date: Fri, 1 Jul 2005 12:17:41 +1000

Hi there,

On 30/06/2005, at 4:40 PM, james o wrote:

when my WOComponent is being built it iterates over items from a Question table. Each questionItem will have a corresponding pulldown menu or check box list built from a Choices table. at this point i can think of two options on storing the values in a Results table:

1. when the WORepetition is creating the pull-downs i can bind the corresponding Results table item to the pull down selection. the downside to this is that sometimes when a question (200 per evaluation) is created a result is not always entered causing blank result row to be inserted. the downside with this method is that it will create more data (blank rows) and won't work w/checkboxes - i'll need a join table for this. the plus side it will require less cpu/code to get the corresponding Question. after importing the existing legacy data i'll have 3 million rows in the results table @ least 1/2 of them will be null...

2. have a "resultsHolderId" column (for lack of better word) in the Question table to store the selected Choices table object.

I wouldn't do either; sounds messy...

I'd Do:
Question <-->> Choice <-->> Result <<--> User

Now, in your WOComponent use a child editing context. Create and insert a result objects per question (for the user) without the relationship set between the result and choice tables. The drop list will be the choices and will automatically update the relationship (see below). Upon submitting the results, your action method will iterate through the results list and delete objects from the ec that have a null result.

e.g.,
// Result.java
// enables you to set your relationship
// from the drop menu in the WOComponent
public void setChoice(Choice value) {
    Choice currentChoice = choice();
    // EOF defines that EOs are equal if EO1 == EO2
    // Thus, no use updating if we're already set
    if ((value != null && !value.equals(currentChoice)) ||
        (currentChoice != null && !current.equals(value)))
    {
        if (currentChoice != null) {
            currentChoice.removeFromResults(this);
        }
        if (value != null) {
            value.addToResults(this);
        }
        takeStoredValueForKey(value, "choice");
    }
}

// WOComponent.java
public Question aQuestion;
public Choice aChoice;
protected NSMutableDictionary results;

public NSArray questionList() {
// your questions bound to the WORepetition
if (questionList == null) {
questionList = EOUtilities.localInstancesOfObjects(localEC, session().questionList());
}
return questionList;
}
public Result aResult() {
Result aResult;


aResult = (Result) results.objectForKey(aQuestion);
if (aResult == null) {
aResult = EOUtilities.createAndInsertInstance(localEC, "Result");
aResult.addObjectToBothSidesOfRelationshipWithKey(user, "user");
results.setObjectForKey(aResult, aQuestion);
}
return aResult;
}
public WOComponent actionMethod() {
Enumeration en;


en = results.objectEnumerator();
while (en.hasMoreElements()) {
Result r = (Result) en.nextElement();
Choice c = r.choice();
if (c == null) {
aResult.removeObjectFromBothSidesOfRelationshipWithKey (user, "user");
localEC.deleteObject(r);
}
}
// save changes to parent EC if applicable
// and return appropriate component
}


// WOComponent.wod
YourRepetition: WORepition {
    list = questionList;
    item = aQuestion;
}
ChoicesPopUpButton: WOPopUpButton {
    list = aQuestion.choices;
    selection = aResult.choice;
    noSelectionString = "-- no selection --";
    item = aChoice;
    displayString = aChoice.toString;
}

this seems like a common design question that i don't feel confident that either one of my solutions is *right* way to do it. any thoughts or criticism greatly appreciated!

with regards, --

LD


_______________________________________________ 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
References: 
 >Design Question... (From: james o <email@hidden>)

  • Prev by Date: Re: put File[] into NSArray ...possible??
  • Next by Date: Re: Design Question...
  • Previous by thread: Design Question...
  • Next by thread: Re: Design Question...
  • Index(es):
    • Date
    • Thread