Re: WORepetition Only Updates on ec.saveChages()
Re: WORepetition Only Updates on ec.saveChages()
- Subject: Re: WORepetition Only Updates on ec.saveChages()
- From: Chuck Hill <email@hidden>
- Date: Mon, 05 Jan 2004 20:52:30 -0800
Drew,
As far as I can see your isInGame variable never gets set. I'm not clear
what you think it should be. There is also a method isInGame() which
should return the correct value, but only *during* the loops of the
WORepetition over (I'm assuming) session.questionList.
More below.
At 10:48 PM 05/01/2004 -0500, Drew Thoeni wrote:
>I have an "Add/Remove" column in a WORepetition that contains two
>WOConditionals (one for add, one for remove). The conditionals are
>bound to a protected boolean called isInGame.
>
Well, no. They are actually bound to the method protected boolean
isInGame(). Which, BTW, should be public or when you move to WO 5.2.2 and
JDK 1.4 things will stop working.
See the docs for NSKeyValueCoding as to why it is using the method.
>The data structure represents "games" which contain many questions. The
>WORep is displaying questions both already in aGame and questions not
>currently assigned to any game. The user can simply click the "Add"
>hyperlink and viola, or similarly the "Remove" link (shown per the
>isInGame variable) and the question is removed from being assigned to
>this game.
>
>So, all this works but the isInGame variable does not get set correctly
>*unless* the user clicks the add or remove link. Each of these (see
>below) update the cache and save changes. For any item in the WORep
>that has been clicked add or remove, the isInGame is set to a correct
>value. For others, even those that should be true, false is the value.
>
>What am I missing here?
>
Also, possibly
>Thanks,
>
>Drew
>
>PS. Comments on my coding style are also very welcome. I'm new at WO
>and Java.
>
>import com.webobjects.foundation.*;
>import com.webobjects.appserver.*;
>import com.webobjects.eocontrol.*;
>import com.webobjects.eoaccess.*;
>
>public class EditGame extends WOComponent {
>
> protected String pageTitle;
> protected Game aGame;
> protected Question aQuestion;
> private EOEditingContext ec = session().defaultEditingContext();
> private EOFetchSpecification fetchSpec;
> Session session = (Session)session();
> protected boolean isInGame;
>
> public EditGame(WOContext context) {
> super(context);
> pageTitle = "Edit Game";
> }
>
> public void setAGame(Game inGame) {
> aGame = inGame; // set in another page
> // get questions
> NSDictionary bindings = new NSDictionary(aGame.gameId(),
>"currentGame");
eew! gameID == SQL thinking. Think objects or foreever fight WO:
NSDictionary bindings = new NSDictionary(aGame, "currentGame");
And update your fetchspec to be game =
> NSArray temp = EOUtilities.objectsWithFetchSpecificationAndBindings(
>ec, "Question", "FetchQuestionsOpenOrAssignedThisGame", bindings);
Is that different from fetch all questions?
> session.questionList = (NSMutableArray)temp;
> }
>
If this is game specific it would be better managed on this page. If it is
global, why not just fetch it once per session instead of once per game?
> protected WOComponent addQuestonToGame() {
> aGame.addToQuestions(aQuestion);
> aQuestion.setGame(aGame);
> ec.saveChanges();
> return null;
> }
>
return context().page(); is slightly more efficient in all cases and much
more efficient in some (large numeber of components, target at end of page).
> protected WOComponent removeQuestionFromGame() {
> aGame.removeFromQuestions(aQuestion);
> aQuestion.setGame(null);
> ec.saveChanges();
> return null;
> }
>
> public ManageGames cancel() {
> ManageGames nextPage = (ManageGames)pageWithName("ManageGames");
> ec.revert();
> return nextPage;
> }
>
You are probably better off creating a new ec for each page than relying on
this to work. Users will back track, open multiple windows, they have many
bad habits.
> protected boolean isInGame() {
> if (aQuestion.gameId() == aGame.gameId()) {
> return true;
> }
> else {
> return false;
> }
> }
>
urk. More of them ID things.
public boolean isInGame() {
return aQuestion.game() == aGame;
}
Chuck
--
Chuck Hill email@hidden
Global Village Consulting Inc. http://www.global-village.net
_______________________________________________
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.