You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Joshua Jackson <jo...@gmail.com> on 2007/05/31 11:44:52 UTC

T5: Inject Entities into Page component

Dear all,

Would it be possible to Inject Entities into my Page component to be
used for Hibernate, so I don't have to write get and set for setting
and getting the value of my object in my Page component?

So I can just write as such:
public void onAction(){
  session.save(myobj)
}

inside my action handler without having to set the value of myobj
manually in the code but instead the value is automatically injected
from the value of HTML form.

I used tapestry-hibernate module for setting up the Session and Session Factory.


Thanks for the help

-- 
YM!: thejavafreak
Blog: http://www.nagasakti.or.id/roller/joshua/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Inject Entities into Page component

Posted by Davor Hrg <hr...@gmail.com>.
i belive howard is planning for a tighter integration of hibernate module
...
don't know is this doable easier since this approach requires a lot code,
I could make sth to handle all entities but here's something so you can play
and see the easynes of tapestry-ioc.

code is not perfect but worked wonderflully both on the page where I list
the reports, a well as on action link

template ...
    <t:loop source="reports" value="report">
        [<t:ActionLink context="reportLink">${report.name
}</t:ActionLink>]<br/>
    </t:loop>

method:
    public Object[] getReportLink() {
        return new Object[] { "en", report };
    }

action method that generates a PDF
    public Object onAction(String lang, AdReport adReport) throws
DocumentException {
.......



the code needed for it to work
first the version vith an dao object (code goes to AppModule):

    public static void contributeTypeCoercer(Configuration<CoercionTuple>
configuration,final AdReportDAO  dao)
    {
      Coercion<AdReport, String> coercion = new Coercion<AdReport, String>()
      {
        public String coerce(AdReport input)
        {
          return input.getId().toString();
        }
      };

      configuration.add(new CoercionTuple<AdReport, String>(AdReport.class,
String.class, coercion));

      Coercion<String, AdReport> coercion2 = new Coercion<String,
AdReport>()
      {
        public AdReport coerce(String input)
        {
          try {
            return dao.findById(Long.parseLong(input), false);
          } catch (NumberFormatException e) {}
          return null;
        }
      };

      configuration.add(new CoercionTuple<String, AdReport>(String.class,
AdReport.class, coercion2));

    }


-----------------------------------------------
the version with session object (code goes to AppModule):

    public static void contributeTypeCoercer(Configuration<CoercionTuple>
configuration,final Session  session)
    {
      Coercion<AdReport, String> coercion = new Coercion<AdReport, String>()
      {
        public String coerce(AdReport input)
        {
          return input.getId().toString();
        }
      };

      configuration.add(new CoercionTuple<AdReport, String>(AdReport.class,
String.class, coercion));

      Coercion<String, AdReport> coercion2 = new Coercion<String,
AdReport>()
      {
        public AdReport coerce(String input)
        {
          try {
            return (AdReport) session.get(AdReport.class,Long.parseLong
(input));
          } catch (NumberFormatException e) {}
          return null;
        }
      };

      configuration.add(new CoercionTuple<String, AdReport>(String.class,
AdReport.class, coercion2));

    }



On 5/31/07, Joshua Jackson <jo...@gmail.com> wrote:
>
> Dear all,
>
> Would it be possible to Inject Entities into my Page component to be
> used for Hibernate, so I don't have to write get and set for setting
> and getting the value of my object in my Page component?
>
> So I can just write as such:
> public void onAction(){
>   session.save(myobj)
> }
>
> inside my action handler without having to set the value of myobj
> manually in the code but instead the value is automatically injected
> from the value of HTML form.
>
> I used tapestry-hibernate module for setting up the Session and Session
> Factory.
>
>
> Thanks for the help
>
> --
> YM!: thejavafreak
> Blog: http://www.nagasakti.or.id/roller/joshua/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>