You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michal Prinke <bo...@icpnet.pl> on 2004/05/07 10:29:08 UTC

Select's submitOnChange() vs. listener method - how to figure out which one is it?

Hello,

I have a form with many text fields and one <select> (@PropertySelection)
that has "submitOnChange" property set to "true".

In form's listener method, how to figure out whether user submitted the whole 
form by clicking its submit button, or only changed the selected value? The 
first case should result in some database operations (INSERTS/UPDATE), while the 
latter should only refresh the page...

Thank you!

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


Re: Updating Hibernate objects in Tapestry - am I doing this correctly?

Posted by John Studarus <st...@jhlconsulting.com>.
  I create the object in the passing page - then I can
use the same page for Add & Edit without worrying
about any initialization or figuring out if I need
to do a save or update.  It cuts the number of pages
I have to develop in half.
  I have a base page called AddEditPage.java which
I derive these Hibernate pages.  When I have the
Botany sample source code online it'll make sense.
  I hope this helps!  It took me a while to figure
out the best way to work with Hibernate.  The
botany.db.Plant is actually generated by the
code generator within the Hibernate-tools package.

        John

HomePage.java

  public void addPlantAction(IRequestCycle cycle) {
    PlantPage next_page = (PlantPage) cycle.getPage("Plant") ;
    Plant plant = new Plant() ;
    next_page.setPlant(plant) ;
    cycle.activate(next_page) ;
  }

  // an edit would look like (i.e. from a foreach)

  public void editPlantAction(IRequestCycle cycle) {
    PlantPage next_page = (PlantPage) cycle.getPage("Plant") ;
    next_page.setPlant(getPlant()) ;  // this would do a getPlant from the foreach
    cycle.activate(next_page) ;
  }

Plant.page

  <property-specification name="plant" type="botany.db.Plant" persistent="yes" />


PlantPage.java:
  public abstract Plant getPlant() ;
  public abstract void setPlant(Plant plant) ;

  public AbstractDatabaseObject getDBO() {
    return getPlant() ;
  }

  public void setDBO(AbstractDatabaseObject dbo) {
    setPlant((Plant)dbo) ;
  }



AddEditPage.java:
  public abstract AbstractDatabaseObject getDBO() ;
  public abstract void setDBO(AbstractDatabaseObject dbo) ;

  public void okSubmit(IRequestCycle cycle)
  {
    ValidationDelegate delegate = (ValidationDelegate)getBeans().getBean("delegate") ;
    if ( delegate.getHasErrors() ) {
      return ;
    }
    try {
      Session session = ((HibernateMonitor)(cycle.getMonitor())).getHibernateSession() ;
      session.saveOrUpdate(getDBO());
      cycle.activate("Home") ;
    } catch (Exception e) {
      e.printStackTrace();
    }
    cycle.activate("Home") ;
  }




On Mon, May 10, 2004 at 06:09:33PM +0200, Michal Prinke wrote:
> Hello,
> 
> Let's say I have such a Hibernate class:
> 
>   public class Person {
>     Long    id,
>     String  name,
>     Company company
>   }
> 
> "id" is Person's unique identifier (primary key), "name" is Person's name
> and "company" is another Hibernate object, with its own fields, connected
> to Person by foreign key.
> 
> MY QUESTION:
> What should be a general approach to inserting/updating such objects
> in Tapestry?
> 
> Below is how I do it. Is it correct? (the code is simplified)
> 
> 
>   <property-specification name="person" type="Person"/>
> 
> 
>   public abstract Person getPerson();
>   public abstract void setPerson(Person p);
> 
>   public void attach()
>   {
>     // initialize an empty transient instance of Person
>     // so Tapestry could fill its fields with incoming form values
>     setPerson(new Person());
>     getPerson().setCompany(new Company());
>   }
> 
>   public void formSubmit()  // listener
>   {
>     // get company by its id
>     if (getPerson().getCompany().getId() != null)
>     {
>       getPerson().setCompany(CompanyDAO.getById(
>         getPerson().getCompany().getId()));
>     }
> 
>     if (getPerson().getId() == null)
>     {
>       // no Person's id -> we are adding a new Person
>       // (using some helper class)
>       PersonDAO.insert(getPerson());
>     }
>     else
>     {
>       // update
>       PersonDAO.update(getPerson());
>     }
>   }
> 
>   public void detach()
>   {
>     // clear class member
>     setPerson(null);
>   }
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org

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


Updating Hibernate objects in Tapestry - am I doing this correctly?

Posted by Michal Prinke <bo...@icpnet.pl>.
Hello,

Let's say I have such a Hibernate class:

   public class Person {
     Long    id,
     String  name,
     Company company
   }

"id" is Person's unique identifier (primary key), "name" is Person's name
and "company" is another Hibernate object, with its own fields, connected
to Person by foreign key.

MY QUESTION:
What should be a general approach to inserting/updating such objects
in Tapestry?

Below is how I do it. Is it correct? (the code is simplified)


   <property-specification name="person" type="Person"/>


   public abstract Person getPerson();
   public abstract void setPerson(Person p);

   public void attach()
   {
     // initialize an empty transient instance of Person
     // so Tapestry could fill its fields with incoming form values
     setPerson(new Person());
     getPerson().setCompany(new Company());
   }

   public void formSubmit()  // listener
   {
     // get company by its id
     if (getPerson().getCompany().getId() != null)
     {
       getPerson().setCompany(CompanyDAO.getById(
         getPerson().getCompany().getId()));
     }

     if (getPerson().getId() == null)
     {
       // no Person's id -> we are adding a new Person
       // (using some helper class)
       PersonDAO.insert(getPerson());
     }
     else
     {
       // update
       PersonDAO.update(getPerson());
     }
   }

   public void detach()
   {
     // clear class member
     setPerson(null);
   }

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


Re: Getting input field's generated NAME?

Posted by Geoff Longman <gl...@intelligentworks.com>.
I think all form field components have a getName() method that contains the
generated name.

When a form field is rewound or rendered it obtains its dynamic name from
its parent From component.

Somebody correct me if I'm wrong.

Geoff
----- Original Message -----
From: "Michal Prinke" <bo...@icpnet.pl>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Friday, May 07, 2004 7:38 AM
Subject: Getting input field's generated NAME?


> Hello,
>
> I'd like to print out name of some input field - not the component name,
> but the value of NAME attribute of <INPUT> tag that is generated
automatically
> by Tapestry in HTML.
>
> E.g.
>
> <input jwcid="usernameTextField@TextField" value="ognl:visit.username">
> <span jwcid="@Insert"
>    value="ognl:components.usernameTextField.generatedInputFieldName"/>
>
> Is there something like this (hypothetical) getGeneratedInputFieldName()?
>
> Thank you!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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


Getting input field's generated NAME?

Posted by Michal Prinke <bo...@icpnet.pl>.
Hello,

I'd like to print out name of some input field - not the component name,
but the value of NAME attribute of <INPUT> tag that is generated automatically 
by Tapestry in HTML.

E.g.

<input jwcid="usernameTextField@TextField" value="ognl:visit.username">
<span jwcid="@Insert"
   value="ognl:components.usernameTextField.generatedInputFieldName"/>

Is there something like this (hypothetical) getGeneratedInputFieldName()?

Thank you!


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


Re: Select's submitOnChange() vs. listener method - how to figure out which one is it?

Posted by John Studarus <st...@jhlconsulting.com>.
  How about two separate forms within the page?
Place the PropertySelection in one and the
text fields in the other.  Or am I missing something?

        John


On Fri, May 07, 2004 at 10:29:08AM +0200, Michal Prinke wrote:
> Hello,
> 
> I have a form with many text fields and one <select> (@PropertySelection)
> that has "submitOnChange" property set to "true".
> 
> In form's listener method, how to figure out whether user submitted the 
> whole form by clicking its submit button, or only changed the selected 
> value? The first case should result in some database operations 
> (INSERTS/UPDATE), while the latter should only refresh the page...
> 
> Thank you!
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org

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


Re: Select's submitOnChange() vs. listener method - how to figure out which one is it?

Posted by Geoff Longman <gl...@intelligentworks.com>.
There may be typos

Template:

<form jwcid="@Form" listener="ognl:listeners.formSubmitted">

    <select jwcid="@PropertySelection" submitOnChange="ognl:true"/>

    <input jwcid="@Submit" listener="ognl:listeners.submitListener"/>
</form>


Spec:

 <property-selection name="realSubmit" type="boolean" persistent="no"/>

Java file

public abstract boolean isRealSubmit();
public abstract void setRealSubmit();

public void submitListener(IRequestCycle cycle) {
       setRealSubmit(true);
}

public void formSubmitted(IRequestCycle cycle) {

    if (isRealSubmit()) {

        do the INSERTS/UPDATE
    } else {

        handle the fact that the PropertySelection submitted on change
    }
}
----- Original Message -----
From: "Michal Prinke" <bo...@icpnet.pl>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Friday, May 07, 2004 4:29 AM
Subject: Select's submitOnChange() vs. listener method - how to figure out
which one is it?


> Hello,
>
> I have a form with many text fields and one <select> (@PropertySelection)
> that has "submitOnChange" property set to "true".
>
> In form's listener method, how to figure out whether user submitted the
whole
> form by clicking its submit button, or only changed the selected value?
The
> first case should result in some database operations (INSERTS/UPDATE),
while the
> latter should only refresh the page...
>
> Thank you!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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