Getting Started - Your First Stateful Project
Getting Started - Your First Stateful Project
- Subject: Getting Started - Your First Stateful Project
- From: Philippe Willems <email@hidden>
- Date: Sat, 09 Feb 2013 11:37:33 +0100
Hi List,
I have no working knowledge of WO or Java or Object Programming, but
have been looking at WO for a number of years reading about it and
working myself through some tutorials left and right. Last time was a
few years back.
Now I picked it up again and have been working through the new "Getting
Started" tutorials Pascal Robert wrote.
Great to see how he puts in so much effort to get people going.
I finally got the "Your First Stateful Project" to work like it should.
<http://wiki.wocommunity.org/display/documentation/Your+First+Stateful+Project>
However, to get it to work, I had to change the java code quite a bit.
I found the page to fetch the data when the "session().loggedAuthor()"
value was still null (before doing the login)
and then for some reason fetching all data in the table BlogEntry.
Finally my working "AdminMainPage.java" code looks like below.
However, I am afraid I am not doing things they are supposed to be done.
Any comments on how I should be doing this ?
All help is welcome...
Also can someone tell me where to go from here ?
Best regards,
Philippe
package your.app.components;
import your.app.Session;
import your.app.model.Author;
import your.app.model.BlogEntry;
import com.webobjects.appserver.WOActionResults;
import com.webobjects.appserver.WOContext;
import com.webobjects.eoaccess.EODatabaseDataSource;
import com.webobjects.eocontrol.EOEditingContext;
import com.webobjects.foundation.NSLog;
import er.extensions.batching.ERXBatchingDisplayGroup;
import er.extensions.components.ERXComponent;
import er.extensions.eof.ERXEC;
public class AdminMainPage extends ERXComponent {
@Override
public Session session() {
return ((Session)super.session());
}
private ERXBatchingDisplayGroup<BlogEntry> _dg;
private EODatabaseDataSource _dataSource;
public AdminMainPage(WOContext context) {
super(context);
EODatabaseDataSource _dataSource = new
EODatabaseDataSource(editingContext(), BlogEntry.ENTITY_NAME);
loadDisplayGroup();
}
public void loadDisplayGroup() {
NSLog.out.appendln("AdminMainPage displayGroup");
NSLog.out.appendln(" - Blog entries for Author =
<"+session().loggedAuthor()+">");
_dg = new ERXBatchingDisplayGroup<BlogEntry>();
_dg.setNumberOfObjectsPerBatch(20);
_dg.setDataSource(_dataSource);
_dg.setObjectArray(BlogEntry.fetchBlogEntries(editingContext(),
BlogEntry.AUTHOR.eq(session().loggedAuthor()),
BlogEntry.LAST_MODIFIED.descs()));
}
public ERXBatchingDisplayGroup<BlogEntry> displayGroup() {
return this._dg;
}
private String _emailAddress;
public String emailAddress() {
return this._emailAddress;
}
public void setEmailAddress(String emailAddress) {
this._emailAddress = emailAddress;
}
private BlogEntry _blogEntryItem;
public void setBlogEntryItem(BlogEntry blogEntryItem) {
this._blogEntryItem = blogEntryItem;
}
public BlogEntry blogEntryItem() {
return this._blogEntryItem;
}
public boolean isLogged() {
return ((session()).loggedAuthor() == null) ? false: true;
}
private EOEditingContext _ec;
public EOEditingContext editingContext() {
if (_ec == null) {
_ec = ERXEC.newEditingContext();
}
return _ec;
}
private String _errorMessage = null;
public String errorMessage() {
return this._errorMessage;
}
public WOActionResults login() {
Author loggedAuthor = Author.validateLogin(editingContext(),
_emailAddress);
if (loggedAuthor != null) {
NSLog.out.appendln("Set SessionAuthor to
<"+loggedAuthor+">");
session().setAuthor(loggedAuthor);
loadDisplayGroup();
} else {
_errorMessage = "Invalid email address";
}
return null;
}
}
|
_______________________________________________
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