WORepetition Only Updates on ec.saveChages()
WORepetition Only Updates on ec.saveChages()
- Subject: WORepetition Only Updates on ec.saveChages()
- From: Drew Thoeni <email@hidden>
- Date: Mon, 5 Jan 2004 22:48:21 -0500
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.
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?
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");
NSArray temp = EOUtilities.objectsWithFetchSpecificationAndBindings(
ec, "Question", "FetchQuestionsOpenOrAssignedThisGame", bindings);
session.questionList = (NSMutableArray)temp;
}
protected WOComponent addQuestonToGame() {
aGame.addToQuestions(aQuestion);
aQuestion.setGame(aGame);
ec.saveChanges();
return null;
}
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;
}
protected boolean isInGame() {
if (aQuestion.gameId() == aGame.gameId()) {
return true;
}
else {
return false;
}
}
}
_______________________________________________
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.