I'm with Todd on this one. For a re-usable general-case component,
sure every call to getPage() is a major mistake. If you're just rolling a
quick and dirty component to use within your own pages though, just doing:

        getPage().getRecord().getFirstName()

        Is like 100 times faster than:

        A) Create a firstName parameter on the component's jwc file.
        B) Set up binding for same and java "placeholder" methods.
        C) Change your .page file to pass the appropriate firstName method
down into the component.

        The above can take me a good 5 minutes, assuming there aren't any
typoes, while I can just "peek" at the page via getPage() in about 2
seconds.

        In any event, I used to feel bad whenever I did it because I was
writing "non-portable" code, but I got over that. If it's a component for my
own app, it really doesn't *have* to be all nice and loosely bound so it
runs well on your app :).

        --- Pat
        
> -----Original Message-----
> From: Todd O'Bryan [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, July 13, 2005 4:50 AM
> To: Tapestry users
> Subject: Re: Newbie with Thread Issues
> 
> Actually, I think having components know about their pages is
> incredibly helpful if you're designing a special-purpose component
> that you're only going to use in a particular application.
> 
> You're right that it's a horrible design for a general-purpose
> component that you'd like to use in lots of environments, but if you
> just want to encapsulate some functionality to clean up your HTML or
> to hide some nasty logic that you don't want to have to look at all
> the time, it seems like it's perfectly reasonable.
> 
> Todd
> 
> On Jul 12, 2005, at 5:33 PM, Jamie Orchard-Hays wrote:
> 
> > This design looks inverted to me.
> >
> > Why do you want a component to know about the page? It seems to me
> > you want to have parameters on the component that can be passed
> > into it from the page.
> >
> > <parameter name="company" required="yes" direction="in"
> > type="java.lang.String"/>
> >
> > then in your java:
> >
> > public abstract void setCompany(String companyName);
> > public abstract String getCompany();
> >
> > A component shouldn't know about the containing page except in the
> > rarest of circumstances.
> >
> > Jamie
> >
> >
> > On Jul 12, 2005, at 4:53 PM, Java Leech wrote:
> >
> >
> >> So do you mean do something like this?
> >>
> >> public abstract class CompanyInfo extends BaseComponent {
> >>
> >>     private boolean dispayLogo = false;
> >>     private Company company;
> >>     private Users user;
> >>
> >>
> >>     /**
> >>      * @return Returns the company.
> >>      */
> >>     public Company getCompany(){
> >>         return(((CompanyProfile) getPage()).getCompany());
> >>     }
> >>
> >>     /**
> >>      * @param company The company to set.
> >>      */
> >>     public void setCompany(Company company) {
> >>         this.company = company;
> >>     }
> >>
> >>     /**
> >>      * @return Returns the user.
> >>      */
> >>     public Users getUser(){
> >>         return(((CompanyProfile) getPage()).getUser());
> >>     }
> >>     /**
> >>      * @param user The user to set.
> >>      */
> >>     public void setUser(Users user) {
> >>         this.user = user;
> >>     }
> >> }
> >>
> >> On Tue, 12 Jul 2005 16:32:37 -0400, "Todd O'Bryan"
> >> <[EMAIL PROTECTED]>
> >> said:
> >>
> >>
> >>> You can only use this component on a page that has getUser() and
> >>> getCompany() defined, right? Create a page superclass that defines
> >>> those two and has the code to get them from the Visit. Then in your
> >>> component you can use ((MyPageSuperClass) getPage()).getUser() and
> >>> similar to get access to them.
> >>>
> >>> You don't really need a separate copy in the component if you can
> >>> get
> >>> it from the Visit, right?
> >>>
> >>> Todd
> >>>
> >>> On Jul 12, 2005, at 4:23 PM, Java Leech wrote:
> >>>
> >>>
> >>>
> >>>> So I guess I don't understand how to initialize these properties
> >>>> for
> >>>> components.
> >>>> If i create a <property-specifications> in my.jwc how do I retrieve
> >>>> the
> >>>> Object I have stored in the Visit()?
> >>>>
> >>>>
> >>>> On Tue, 12 Jul 2005 15:59:22 -0400, "Jamie Orchard-Hays"
> >>>> <[EMAIL PROTECTED]> said:
> >>>>
> >>>>
> >>>>
> >>>>> You need to learn some Tapestry conventions. The first is that
> >>>>> when
> >>>>> you have page or component properties, you generally should not
> >>>>> define them in the Java file with instance variables and get/
> >>>>> setters.
> >>>>> What you should do  is define them in your .page or .jwc file as
> >>>>> <property-specifications>. When you do this, Tapestry will
> >>>>> handle the
> >>>>> initialization they need to be cleaned up for page pooling
> >>>>> (pages are
> >>>>> pooled for performance).
> >>>>>
> >>>>> When you have a page or component property that needs to be
> >>>>> accessed
> >>>>> inside your java file, then you make an abstract getter and/or
> >>>>> setter:
> >>>>> public abstract String getSomeProperty();
> >>>>> public abstract void setSomeProperty();
> >>>>>
> >>>>> Jamie
> >>>>>
> >>>>> On Jul 12, 2005, at 2:50 PM, Java Leech wrote:
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>> Could someone guide me in the right direction here?
> >>>>>> Here is the code for a component that I have:
> >>>>>>
> >>>>>> public class CompanyInfo extends BaseComponent {
> >>>>>>     private Users user = new Users();
> >>>>>>     private Company company = new Company();
> >>>>>>     private boolean dispayLogo = false;
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>     /**
> >>>>>>      * @return Returns the company.
> >>>>>>      */
> >>>>>>     public Company getCompany() {
> >>>>>>         Visit visit = (Visit) getPage().getVisit();
> >>>>>>         return (visit.getCurrentCompany());
> >>>>>>     }
> >>>>>>     /**
> >>>>>>      * @param company The company to set.
> >>>>>>      */
> >>>>>>     public void setCompany(Company company) {
> >>>>>>         this.company = company;
> >>>>>>     }
> >>>>>>     /**
> >>>>>>      * @return Returns the user.
> >>>>>>      */
> >>>>>>     public Users getUser() {
> >>>>>>         Visit visit = (Visit) getPage().getVisit();
> >>>>>>         Users u = visit.getUsers();
> >>>>>>         return u;
> >>>>>>     }
> >>>>>>     /**
> >>>>>>      * @param user The user to set.
> >>>>>>      */
> >>>>>>     public void setUser(Users user) {
> >>>>>>         this.user = user;
> >>>>>>     }
> >>>>>>     ...../
> >>>>>> }
> >>>>>>
> >>>>>> When I log in with two different browsers on different machines I
> >>>>>> get
> >>>>>> the following exception:
> >>>>>> Unable to resolve expression 'company.name' for
> >>>>>> [EMAIL PROTECTED]
> >>>>>> [CompanyProfile/compInfo].
> >>>>>> binding: ExpressionBinding[CompanyProfile/compInfo company.name]
> >>>>>> location: context:/WEB-INF/CompanyInfo.html, line 12
> >>>>>>
> >>>>>> ognl.OgnlException
> >>>>>> source is null for getProperty(null, "name")
> >>>>>>
> >>>>>> Users() and Company() are my persistant Hibernate Classes.
> >>>>>> What is
> >>>>>> the
> >>>>>> best way to do this?  Basically this component shows information
> >>>>>> about
> >>>>>> the current company that the user belongs to.  I have stored the
> >>>>>> Users()
> >>>>>> in the Visit and want to pull up this information.
> >>>>>> Thanks.
> >>>>>> ~chris
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> On Tue, 12 Jul 2005 11:00:31 -0500, "Joel Trunick"
> >>>>>> <[EMAIL PROTECTED]> said:
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>>
> >>>>>>> It's caused because the page is cached. It still has the old
> >>>>>>> "Users"
> >>>>>>> object with the values filled in the first time. Something
> >>>>>>> like the
> >>>>>>> following will fix (I personally user a getter with lazy
> >>>>>>> initialization,
> >>>>>>> and initialize users to null):
> >>>>>>>
> >>>>>>> public void initialize() {
> >>>>>>>   Users users = new Users();
> >>>>>>> }
> >>>>>>>
> >>>>>>> Joel
> >>>>>>>
> >>>>>>> -----Original Message-----
> >>>>>>> From: Java Leech [mailto:[EMAIL PROTECTED]
> >>>>>>> Sent: Tuesday, July 12, 2005 9:25 AM
> >>>>>>> To: [email protected]
> >>>>>>> Subject: Newbie with Thread Issues
> >>>>>>>
> >>>>>>> I have posted this on the forum but it seems there is not to
> >>>>>>> much
> >>>>>>> action
> >>>>>>> there.  So I'll try the mailing list.
> >>>>>>>
> >>>>>>> I'm not sure what I am doing wrong but I seem to be having some
> >>>>>>> serious
> >>>>>>> thread problems. I have been developing an app for about a
> >>>>>>> week and
> >>>>>>> today was the first time I brought up a browser on another
> >>>>>>> machine
> >>>>>>> to my
> >>>>>>> webapp. I knew something was wrong immediatly when my login form
> >>>>>>> was
> >>>>>>> autofilled with the values that I used in the first browser.
> >>>>>>>
> >>>>>>> After trying to log in got a bunch of null value exceptions and
> >>>>>>> can't
> >>>>>>> ever log back in with out restarting jboss. I am using
> >>>>>>> Hibernate3 and
> >>>>>>> Tapestry 3.03 running on jboss.
> >>>>>>>
> >>>>>>> Here is a code snippet from my login component:
> >>>>>>>
> >>>>>>> public abstract class NavLogin extends BaseComponent implements
> >>>>>>> IForm{
> >>>>>>>
> >>>>>>>    private ICallback callback;
> >>>>>>>    private Users users = new Users();
> >>>>>>>
> >>>>>>>     public void setCallback(ICallback callback) {
> >>>>>>>         this.callback = callback;
> >>>>>>>     }
> >>>>>>>
> >>>>>>>    public void formSubmit(IRequestCycle cycle){
> >>>>>>>       //Form Validation
> >>>>>>>       ValidationDelegate delegate =
> >>>>>>>       (ValidationDelegate)getBeans().getBean("delegate");
> >>>>>>>
> >>>>>>>       //If no errors add the user
> >>>>>>>       if(!delegate.getHasErrors()){
> >>>>>>>          System.err.println("Users: "+ getUsers().getEmail() +
> >>>>>>>                " Logging in with password: "+
> >>>>>>>                HashUtils.md5Sum(getUsers().getPassword()));
> >>>>>>>          Users authUser = authenticate();
> >>>>>>>          if(authUser != null){
> >>>>>>>             Visit visit = (Visit) getPage().getVisit();
> >>>>>>>             visit.setUsers(authUser);
> >>>>>>>
> >>>>>>> if(authUser.getRole().getType().equalsIgnoreCase("provider")){
> >>>>>>>                cycle.activate("CompanyProfile");
> >>>>>>>             }
> >>>>>>>          }
> >>>>>>>       }
> >>>>>>>    }
> >>>>>>>    /**
> >>>>>>>     * Authenticate the user attempting to log in
> >>>>>>>     * @return
> >>>>>>>     */
> >>>>>>>    public Users authenticate(){
> >>>>>>>       UserDAO dao = new UserDAO();
> >>>>>>>       Users aUser = dao.authUser(getUsers().getEmail(),
> >>>>>>>       HashUtils.md5Sum(getUsers().getPassword()));
> >>>>>>>       return(aUser);
> >>>>>>>    }
> >>>>>>>
> >>>>>>> --
> >>>>>>> http://www.fastmail.fm - The professional email service
> >>>>>>>
> >>>>>>>
> >>>>>>> ----------------------------------------------------------------
> >>>>>>> ---
> >>>>>>> --
> >>>>>>> To unsubscribe, e-mail: tapestry-user-
> >>>>>>> [EMAIL PROTECTED]
> >>>>>>> For additional commands, e-mail: tapestry-user-
> >>>>>>> [EMAIL PROTECTED]
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> ----------------------------------------------------------------
> >>>>>>> ---
> >>>>>>> --
> >>>>>>> To unsubscribe, e-mail: tapestry-user-
> >>>>>>> [EMAIL PROTECTED]
> >>>>>>> For additional commands, e-mail: tapestry-user-
> >>>>>>> [EMAIL PROTECTED]
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>
> >>>>>> --
> >>>>>> http://www.fastmail.fm - And now for something completely
> >>>>>> different&#8230;
> >>>>>>
> >>>>>>
> >>>>>> -----------------------------------------------------------------
> >>>>>> ---
> >>>>>> -
> >>>>>> To unsubscribe, e-mail: tapestry-user-
> >>>>>> [EMAIL PROTECTED]
> >>>>>> For additional commands, e-mail: tapestry-user-
> >>>>>> [EMAIL PROTECTED]
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>> ------------------------------------------------------------------
> >>>>> ---
> >>>>> To unsubscribe, e-mail: tapestry-user-
> >>>>> [EMAIL PROTECTED]
> >>>>> For additional commands, e-mail: tapestry-user-
> >>>>> [EMAIL PROTECTED]
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>
> >>>> --
> >>>> http://www.fastmail.fm - Access all of your messages and folders
> >>>>                           wherever you are
> >>>>
> >>>>
> >>>> -------------------------------------------------------------------
> >>>> --
> >>>> To unsubscribe, e-mail: tapestry-user-
> >>>> [EMAIL PROTECTED]
> >>>> For additional commands, e-mail: tapestry-user-
> >>>> [EMAIL PROTECTED]
> >>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>>
> >>> --------------------------------------------------------------------
> >>> -
> >>> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>> For additional commands, e-mail: tapestry-user-
> >>> [EMAIL PROTECTED]
> >>>
> >>>
> >>>
> >>
> >> --
> >> http://www.fastmail.fm - Does exactly what it says on the tin
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: tapestry-user-
> >> [EMAIL PROTECTED]
> >>
> >>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to