Re: looking for example wicket and hibernate

2009-12-25 Thread Janning Vygen
Hi 

we have been starting with our hibernate/spring/wicket app a few weeks ago and 
its quite easy. We do it with maven2 like this:

i show you some snippets, please ask me if you have any further questions:

in your pom.xml:
=
properties
wicket.version1.4.5/wicket.version
/properties
...
dependency
groupIdorg.apache.wicket/groupId
artifactIdwicket/artifactId
version${wicket.version}/version
/dependency
dependency
groupIdorg.apache.wicket/groupId
artifactIdwicket-extensions/artifactId
version${wicket.version}/version
/dependency

dependency
groupIdorg.apache.wicket/groupId
artifactIdwicket-spring/artifactId
version${wicket.version}/version
exclusions
exclusion
groupIdorg.springframework/groupId
artifactIdspring/artifactId
/exclusion
/exclusions
/dependency


web.xml
=
?xml version=1.0 encoding=ISO-8859-1?
web-app xmlns=http://java.sun.com/xml/ns/j2ee; 
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
xsi:schemaLocation=http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd;
version=2.4

display-namewicket/display-name

filter
filter-namewicket.wicket/filter-name

filter-classorg.apache.wicket.protocol.http.WicketFilter/filter-class
init-param
param-nameapplicationClassName/param-name
param-valueorg.yourapp.MyApplication/param-value
/init-param
/filter

filter-mapping
filter-namewicket.wicket/filter-name
url-pattern/*/url-pattern
/filter-mapping
/web-app

you can start the spring context directly in your web.xml, but I wanted to 
start my SpringApplication manually in my Application class:

in your MyApplication.java
=
public class MyApplication extends WebApplication

@Override
protected void init ( )
{
 WebApplicationContext ctx = start_your_spring_context_here
addComponentInstantiationListener(new SpringComponentInjector(this, 
ctx, 
true));

   }
@Override
public RequestCycle newRequestCycle ( Request request, Response 
response )
{
return new HibernateRequestCycle(this, (WebRequest) request, 
(WebResponse) 
response);
}


our session per RequestCycle Implemenatation:
=
public class HibernateRequestCycle extends WebRequestCycle
{
SessionFactory  sessionFactory;

public HibernateRequestCycle ( JlotApplication application, WebRequest 
request, Response response )
{
super(application, request, response);
this.sessionFactory = (SessionFactory) 
application.getApplicationContext().getBean(sessionFactory);
}

@Override
protected void onBeginRequest ( )
{
if 
(!TransactionSynchronizationManager.hasResource(sessionFactory))
{
Session session = 
SessionFactoryUtils.getSession(sessionFactory, true);

TransactionSynchronizationManager.bindResource(sessionFactory, new 
SessionHolder(session));
}
super.onBeginRequest();
}

@Override
protected void onEndRequest ( )
{
SessionHolder sessionHolder = (SessionHolder) 
TransactionSynchronizationManager.unbindResource(sessionFactory);
SessionFactoryUtils.closeSession(sessionHolder.getSession());
super.onEndRequest();
}
}

wherever you need a Spring bean you can inject it like this:

@SpringBean
Repository  repository;

public MyClass()
{
InjectorHolder.getInjector().inject(this);
}

if you have a wicket component you do not need this line:
 
InjectorHolder.getInjector().inject(this);


then read about detachable Models! Its quite important to understand it if you 
use hibernate. 

we use an entityModel like this one:
http://wicketinaction.com/2008/09/building-a-smart-entitymodel/

if you like i can send you more source code, but i got it working just by 
reading wicket in action, which is am excellent book. 

our software will be open source soon, so i can send you the complete source 
code if you like. 

kind regards
Janning

On Thursday 24 December 2009 06:42:57 Johan den Boer wrote:
 

Re: looking for example wicket and hibernate

2009-12-24 Thread nino martinez wael
Theres also wicket Iolite, or I think the legup by jweekend..

2009/12/24 Martin Makundi martin.maku...@koodaripalvelut.com:
 Do not mix hibernate and wicket (web gui). Keep your persistence logic
 somewhere else.

 However, if you want only wicket-spring integration you can find some
 here: http://www.wicket-library.com/wicket-examples/spring/

 **
 Martin

 2009/12/24 Johan den Boer johanj.denb...@gmail.com:
 Hi

 I am looking for a real working example on wicket and hibernate. I have read
 the books 'Wcket in Action', 'Pro Wicket' and other books but none of them
 give a real working example. Can somebody point me to a real working example
 or can sent to me.

 The most problem i have with the configuration in web.xml and using the
 spring integration.

 --
 regards,

 John


 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: looking for example wicket and hibernate

2009-12-23 Thread Martin Makundi
Do not mix hibernate and wicket (web gui). Keep your persistence logic
somewhere else.

However, if you want only wicket-spring integration you can find some
here: http://www.wicket-library.com/wicket-examples/spring/

**
Martin

2009/12/24 Johan den Boer johanj.denb...@gmail.com:
 Hi

 I am looking for a real working example on wicket and hibernate. I have read
 the books 'Wcket in Action', 'Pro Wicket' and other books but none of them
 give a real working example. Can somebody point me to a real working example
 or can sent to me.

 The most problem i have with the configuration in web.xml and using the
 spring integration.

 --
 regards,

 John


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org