• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Invoking a component with arguments in WOD
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Invoking a component with arguments in WOD


  • Subject: Re: Invoking a component with arguments in WOD
  • From: Johann Werner <email@hidden>
  • Date: Wed, 19 Sep 2007 08:58:10 +0200

Am 19.09.2007 um 02:43 schrieb Lachlan Deck:

On 19/09/2007, at 8:15 AM, Lachlan Scott wrote:

In our application, we have a log in component which adds a User object
to the Session if the supplied credentials are correct.


For testing purposes, we use a 'component menu' component which displays
a list of available components, and provides action methods to display
them individually.


We can write an action method in the menu to do a login and then display
the component, like this (pseudo code)


Public WOComponent doLoginAndCallNewPage(){
	// do usual login stuff
	// return the actual page we want
}

Which is all well and good, but feels clumsy, and hard codes the login
variables. I wondered if we couldn't somehow call the desired page and
address its user variable from the WOD, something like this:


MyWebObjectName : MyDesiredComponentName {
	user = <some construct to set a User to this variable>;
}


Seems to me that your code will not work properly as your function is declared to return...


Sure...

-- CurrentPage.java --
public User fechedUser() {

... an object of type User

	if ( session().hasUser() ) {
		return session().user();
	}
	else if ( ! hasCredentials() )
		return this;

but here a WOComponent is returned.

// fetch user from credentials
try {
NSDictionary creds = new NSMutableDictionary();
creds.setObjectForKey( userName(), User.UserNameKey );
creds.setObjectForKey( ..... );
session().setUser( ( User )EOUtilities.objectMatchingValues( ec, User.ENTITY_NAME, creds ) );
return fetchedUser();
}
catch ( EOUtilities.MoreThanOneException e ) {
logger.error( "Mayday... no unique constraints on database!" );
throw new NSForwardException( "Woops..." ... );
}
catch ( EOObjectNotAvailableException e ) {
setCredentialsValue( false );
return this;

Here also a wrong return type.

I think you should return null in these two cases and check in the MyDesiredComponentName component for null value and redirect back to the login page if true.

jw

	}
}

MyWebObjectName : MyDesiredComponentName {
	user = fetchedUser;
}

-- MyDesiredComponentName.java --
public User loggedInUser() {
	if ( _user == null )
		_user = ( User )valueForBinding( "user" );
	return _user;
}

with regards,
--

Lachlan Deck



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40isd.uni-stuttgart.de


This email sent to email@hidden

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

  • Follow-Ups:
    • Re: Invoking a component with arguments in WOD
      • From: Lachlan Deck <email@hidden>
References: 
 >Invoking a component with arguments in WOD (From: "Lachlan Scott" <email@hidden>)
 >Re: Invoking a component with arguments in WOD (From: Lachlan Deck <email@hidden>)

  • Prev by Date: Re: Creating new object results in an out of memory error
  • Next by Date: Weird EOExceptions
  • Previous by thread: Re: Invoking a component with arguments in WOD
  • Next by thread: Re: Invoking a component with arguments in WOD
  • Index(es):
    • Date
    • Thread