Hi Dan,

when you do

   private Firm firm = (Firm)
getContext().getDataContext().newObject(Firm.class);

firm is being assigned a value as soon as the action bean is instantiated.
That means that Stripes has not had the chance to set a context when you try
to retrieve it.

A number of options to achieve what you want are:

1) loading the firm inside the handler method [you showed that];
2) using a @Before method;
3) creating a TypeConverter for your firm.

Regards,
  Levi

On Fri, Feb 27, 2009 at 3:34 PM, Dan Cane <[email protected]> wrote:

> Greet all -
>
> First off, a truly wonderful framework here. I'm a huge fan of how quick
> effective stripes truly is.
>
> Here's my newbish question. I've selected Apache Cayenne for my ORM
> framework
> for a number
> of reasons, and I'm stumped as to how to "reuse" my database context. From
> the
> cayenne docs
> located at http://cayenne.apache.org/doc/web-applications.html I gather
> that
> instead of creating a
> new database context inside each bean (which works, but as you can imagine
> is
> not a good
> performance pattern) I should be using the magic "cayenne voodoo which can
> re-use the
> database context attached to the HttpSession object."
>
> ** prepare yourself for a very newb statement that I'm hopeful someone out
> there
> is willing to handhold me through **
>
> Ok - so I get that I'm supposed to get the dataContext from the Util which
> can
> pop it off session:
>
> HttpSession session = ...;
> DataContext context = ServletUtil.getSessionContext(session);
>
> So - I figure I already extended ActionBean and ActionBeanContext so why
> not
> just put a method
> in my new context to get the data context..
>
> -snip-
> public class BKFActionBeanContext extends ActionBeanContext {
>
>        public void setUser(User currentUser) {
>                getRequest().getSession().setAttribute("user", currentUser);
>        }
>
>        public User getUser() {
>                return (User)
> getRequest().getSession().getAttribute("user");
>        }
>
>        public DataContext getDataContext() {
>                return
> ServletUtil.getSessionContext(getRequest().getSession());
>        }
>
>        /** Logs the user out by invalidating the session. */
>        public void logout() {
>                getRequest().getSession().invalidate();
>        }
>
> }
> -snip-
>
> Ok - and lo-and-behold it WORKS (sometimes). I found that inside of things
> like
> Validate methods
> and Resolutions I can quite easily use getContext().getDataContext() and it
> has
> exactly what I need.
>
> BUT -- (someone smack me for this) when I attempt to use the data context
> while
> declaring a new
> variable for my object I find that getContext (stripes) returns null, so of
> course my
> getContext().getDataContext() throws a NPE exception.
> (I really should have taken classes in school since I'm sure someone can
> explain
> why that's
> a no-no)
>
> e.g
> -- this is not working --
> @UrlBinding("/RegisterFirm.action")
> public class RegisterFirmActionBean extends BKFActionBean {
>
>    @ValidateNestedProperties({
>        @Validate(...),
>    })
>    private Firm firm = (Firm)
> getContext().getDataContext().newObject(Firm.class);
> -- end what throws a NPE --
>
> Ok - so I've on day 2 of trying things and I'm at the point of asking for
> help.
> Help. :)
>
> Is there a better/different way to new up a "Firm" object and then set the
> object properties,
> e.g. in my Resolution do a
>    @DefaultHandler
>    public Resolution view() {
>         this.firm = (Firm)
> getContext().getDataContext().newObject(Firm.class);
>         return new ForwardResolution("/RegisterFirm.jsp");
>    }
>
> or something else all together.
> I would think it's desirable to have my data context on the session, but...
>
> Anyways, THANK YOU for taking some time to help me out.
>
> Dan
>
>
>
>
>
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco,
> CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the
> Enterprise
> -Strategies to boost innovation and cut costs with open source
> participation
> -Receive a $600 discount off the registration fee with the source code:
> SFAD
> http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> Stripes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to