Re: login docs
Re: login docs
- Subject: Re: login docs
- From: "Jonathan Fleming" <email@hidden>
- Date: Sat, 08 Mar 2003 19:49:59 +0000
Kenny you will recieve this in two parts, it's the full working code of the
Authors application that you have been tying to put together.
It should be fine just take the relevant pages and and overwrite the code
you have created or simple overwite the code that's not working for you.
This post has the Session.java, Main.java and Author.java The next one will
have AuthorBookEdit.java and Book.java
// Generated by the WebObjects Wizard
import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
public class Session extends WOSession {
private EOFetchSpecification fetchSpec;
/** @TypeInfo Author */
protected NSMutableArray authorList;
// Constructor
public Session() {
super();
// build fetch specification
fetchSpec = new EOFetchSpecification("Author", null, null);
// fetch
fetchAuthorList();
}
public void fetchAuthorList() {
// get editing context
EOEditingContext ec = defaultEditingContext();
// fetch
authorList = new
NSMutableArray(ec.objectsWithFetchSpecification(fetchSpec));
}
public boolean addAuthor(Author author) {
// add only if the author is not already in the list
if (! authorList.containsObject(author)) {
// add author to list
authorList.addObject(author);
// insert author into editing context
defaultEditingContext().insertObject(author);
return true;
}
else {
return false;
}
}
public void deleteAuthor(Author author) {
// remove author from authorList
authorList.removeObject(author);
// get objects editing context
EOEditingContext ec = author.editingContext();
// remove author from object graph
ec.deleteObject(author);
}
}
===============================================
// Generated by the WebObjects Wizard Sun Mar 31 16:30:48 GMT 2002
import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;
public class Main extends WOComponent {
private EOEditingContext editingContext;
protected Author author;
protected Author authorItem;
private Session session;
// Constuctor
public Main(WOContext context) {
super(context);
// get session
session = (Session)session();
// get editing context
editingContext = session.defaultEditingContext();
// create a new author object (where form data is stored)
author = new Author();
}
// The addAuthor Method here uses the addAuthor method in
// Session.java
public WOComponent addAuthor() {
if (session.addAuthor(author)) {
// create a new author
author = new Author();
}
return null;
}
// The deleteAuthor Method here uses the deleteAuthor method in
// Session.java
public WOComponent deleteAuthor() {
session.deleteAuthor(authorItem);
return null;
}
public WOComponent editAuthor() {
// set the author to edit to the one the user selected
author = authorItem;
return null;
}
/* The editBooks method needs to send the author whose books are to be
edited to the AuthorBookEdit component (the next page to be displayed).
This is how it's done: The revertChanges method here uses default
editing context and the fetchAuthorList method in Session.java */
public WOComponent revertChanges() {
// revert object graph
editingContext.revert();
// refetch
session.fetchAuthorList();
return null;
}
public WOComponent saveChanges() {
// save changes made in editing context to object store
editingContext.saveChanges();
return null;
}
public WOComponent updateAuthor() {
// create a new author
author = new Author();
return null;
}
// The editBooks method here sends Author object to
// AuthorBookEdit component
public AuthorBookEdit editBooks() {
AuthorBookEdit nextPage =
(AuthorBookEdit)pageWithName("AuthorBookEdit");
// Initialize your component here
nextPage.setAuthor(authorItem);
return nextPage;
}
}
============================================
// Author.java
// Created on Mon Apr 08 02:27:12 2002 by Apple EOModeler Version 5.0
import java.math.*;
import java.util.*;
import com.webobjects.foundation.*;
import com.webobjects.eocontrol.*;
public class Author extends EOGenericRecord {
public Author() {
super();
setLastName("*required*");
setFirstName("*optional*");
}
public String firstName() {
return (String)storedValueForKey("firstName");
}
public void setFirstName(String value) {
takeStoredValueForKey(value, "firstName");
}
public String lastName() {
return (String)storedValueForKey("lastName");
}
public void setLastName(String value) {
takeStoredValueForKey(value, "lastName");
}
public String fullName() {
String first = firstName();
String last = lastName();
String full;
if ((first != null) && (! (first.equals("")))) {
full = last + ", " + first;
}
else {
full = last;
}
return full;
}
public NSArray books() {
return (NSArray)storedValueForKey("books");
}
public void setBooks(NSMutableArray value) {
takeStoredValueForKey(value, "books");
}
public void addToBooks(Book object) {
NSMutableArray array = (NSMutableArray)books();
willChange();
array.addObject(object);
}
public void removeFromBooks(Book object) {
NSMutableArray array = (NSMutableArray)books();
willChange();
array.removeObject(object);
}
}
From: Kenny Sabarese <email@hidden>
To: email@hidden
Subject: login docs
Date: Sat, 8 Mar 2003 11:18:39 -0800
i'm looking to make a simple login against the openbase DB as my first
real foray into WO (basically something that isn't in the book)
is there a place for directions and sample code. i tried to modify the
"authors" example in the WO book but i got a bunch of errors.
any hints at all would be great. i'm looking for something extremely
basic. if that is possible.
----------------------
Kenny Sabarese
email@hidden
http://kenny.sabarese.net
_________________________________________________________________
Surf together with new Shared Browsing
http://join.msn.com/?page=features/browse&pgmarket=en-gb&XAPID=74&DI=1059
_______________________________________________
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.