I have some code (below) that functions as expected. However, I just noticed when the user has completed this method, and is returned to the nextPage, if they refresh the nextPage the database is updated again with the same selections that were made in this method.
I'm pretty sure this is something I'm doing incorrectly. And am hoping it's obvious to you long-timers. Thoughts? (Other comments on my code is also, always, welcome.)
Regards,
Drew
To make the code easier to read, this is a review site. An item has many reviews. The method here is recording if someone found the review in question useful, not useful, or didn't vote.
private Session session = (Session)session(); private EOEditingContext ec = session().defaultEditingContext();
<snip>
public BrowseReviewPage returnToBrowseReviewPage() { if ( null != usefulRating ) { // user didn't rate if this review was useful. if ( usefulRating.intValue() == 1 ) { reviewItem().setUsefulTotalVoteCount( new Integer( reviewItem().usefulTotalVoteCount().intValue() + 1 ) ); reviewItem().setUsefulPositiveVoteCount( new Integer( reviewItem().usefulPositiveVoteCount().intValue() + 1 ) ); } if ( usefulRating.intValue() == 2 ) { reviewItem().setUsefulTotalVoteCount( new Integer( reviewItem().usefulTotalVoteCount().intValue() + 1 ) ); } } ec.saveChanges(); BrowseReviewPage nextPage = ( BrowseReviewPage )pageWithName( "BrowseReviewPage" ); nextPage.passObjects( reviewItem().toItem() ); return nextPage; }
|