You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by netdawg <ne...@yahoo.com> on 2012/04/21 09:31:21 UTC

Reuse Edit/Create for Query by Example

Search is next step from the following thread whereby an UPDATE form may be
REUSED to ADD a database record: 

http://tapestry.1045711.n5.nabble.com/Reuse-Edit-Create-td5643323.html

The same form should do Query By Example (QBE) supported as by Hibernate: 

http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html/ch17.html#querycriteria-examples

So the same exact form is now used to ADD, UPDATE or QBE.  

For the sake of completeness, here is EditPerson from 

http://tapestry.apache.org/hibernate-user-guide.html

modified for dual service as Edit/Create

public class EditPerson
{

  @Inject
  private Session session;

  @PageActivationContext
  @Property
  private Person person;

  @InjectPage
  private Persons persons;

  void onActivate(Person person)
  {
    this.person = person;
  }

  Object onPassivate() { return person; }

  @CommitAfter
  Object onSuccess()
  {
    session.saveOrUpdate(person);
    return persons;
  }
}


Persons.java is simply doing listing


public class Persons
{
	 
  @Property
  private Person person;

  @Inject
  private Session session;
  
  public List<Person> getPersons()
  {
    return session.createCriteria(Person.class).list();
  }
  
}

Corresponding tmls are: 

EditPerson: <t:beaneditform object="person" />
Persons: <t:grid source="persons" />


which are inserted between the usual 

<html t:type="layout" title="Persons"
      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
      xmlns:p="tapestry:parameter">
</html>





--
View this message in context: http://tapestry.1045711.n5.nabble.com/Reuse-Edit-Create-for-Query-by-Example-tp5655916p5655916.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Reuse Edit/Create for Query by Example

Posted by netdawg <ne...@yahoo.com>.
Instead of eventlinks and the ch kit wrapper for button...just use: 

<t:submit t:id="search" value="QBE Search" />

http://tapestry.apache.org/current/apidocs/index.html?org/apache/tapestry5/corelib/components/EventLink.html

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Reuse-Edit-Create-for-Query-by-Example-tp5655916p5656051.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Reuse Edit/Create for Query by Example

Posted by netdawg <ne...@yahoo.com>.
Most likely, the solution is to simply segregate Search (QBE) from
Create/Update using EventLink.   That is, segregate the Search workflow
instead of overloading Create/Update.  This is to bypass the (default?)
onSuccess and therefore prevent the EditPage from Adding a Person instead of
doing QBE.   

# QBE Search 

To style this as a Search BUTTON instead of a link, use ChenilleKit as in: 

http://jumpstart.doublenegative.com.au/jumpstart/examples/styling/linksandsubmits1



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Reuse-Edit-Create-for-Query-by-Example-tp5655916p5656016.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Reuse Edit/Create for Query by Example

Posted by netdawg <ne...@yahoo.com>.
To do QBE, I would simply modify the getPersons method in Persons.java 

public List<Person> getPersons()
{
    return session.createCriteria(Person.class).add( Example.create(person)
).list();
} 

This would use the person property to list persons list.  Of course, I would
check for person=nulls etc to protect the above and list all if so...the
above is just to simplify.   

However, the input form needs another button in addition to Create/Update. 
Lets say I even manually add it - and call it Search.

How does the EditPerson NOT end up creating a new Person?  In the Struts
world this would simply be a search method within same PersonAction class. 
And the same Person object on the Valuestack would be used as an Hibernate
Example to drive search instead of ending up as parameter of AddPerson and
creating a new record.  

And so on..., generally, how does one single form submit be wired to support
multiple actions?  Or is this frowned upon as bad practice?



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Reuse-Edit-Create-for-Query-by-Example-tp5655916p5655931.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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