Re: Wicketstuff updated!

2010-04-02 Thread nino martinez wael
is that when running a test or?

2010/4/2 新希望软件 -- 俞宏伟 nhsoft@gmail.com:
 i found thant push component has some problem. after update push compenet to
 1.4.7-snapshot, the application throws some error message:

 04-02 09:34:55.546[   RequestCycle.java:1521:ERROR] There is no
 application attached to current thread http-8081-4
 org.apache.wicket.WicketRuntimeException: There is no application attached
 to current thread http-8081-4
at org.apache.wicket.Application.get(Application.java:179)
at org.apache.wicket.Component.getMarkupId(Component.java:1542)
at org.apache.wicket.Component.getMarkupId(Component.java:1578)
at
 org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getPreconditionScript(AbstractAjaxTimerBehavior.java:140)
at
 org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.generateCallbackScript(AbstractDefaultAjaxBehavior.java:170)
at
 org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getCallbackScript(AbstractAjaxTimerBehavior.java:127)
at
 org.apache.wicket.ajax.AbstractAjaxTimerBehavior.getJsTimeoutCall(AbstractAjaxTimerBehavior.java:120)
at
 org.apache.wicket.ajax.AbstractAjaxTimerBehavior.respond(AbstractAjaxTimerBehavior.java:163)
at
 org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:286)
at
 org.apache.wicket.request.target.component.listener.BehaviorRequestTarget.processEvents(BehaviorRequestTarget.java:119)
at
 org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at
 org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at
 org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
at
 org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:312)
at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
 org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:359)
at
 org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
at
 org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at
 org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at
 org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:174)
at
 org.springframework.security.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:99)
at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at
 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at
 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at
 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at
 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at
 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at
 org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)

 my wicket version is 1.4.7.


 On Thu, Apr 1, 2010 at 20:50, nino martinez wael 
 nino.martinez.w...@gmail.com wrote:

 Well, one could see that in version x.x.x of wicketstuff core project
 x was excluded.. It was just a proposition. As with everything else it
 has pro's and con's.

 2010/4/1 Jeremy Thomerson jer...@wickettraining.com:
  there's already an attic - why create a new one?  it will just generate
 more
  emails to the list whining about i can't find such and such - by those
 who
  can't use the search function well.  there's nothing special about an
  ex-core project that means it needs its own attic
 
  --
  Jeremy Thomerson
  http://www.wickettraining.com
 
 
 
  On Wed, Mar 31, 2010 at 11:57 AM, nino martinez wael 
  nino.martinez.w...@gmail.com wrote:
 
  I guess we could start a branch, called wicketstuff-core-attic. Then
  upgrade them to latest wicket version and see if they work and if not,
  then remove them. Unless someone wants to fix the errors.
 
  2010/3/28 Major Péter majorpe...@sch.bme.hu:
   JavaEE-Inject is tested, and OK.
  
   

Image Upload Using TinyMCE Within Wicket Framework

2010-04-02 Thread Michał Letyński

I wrote an article for following topic:
Image upload using TinyMce within Wicket Framework
Article is based on functionality which i wrote to my project. I wrote it
since during investigation i saw high demand for such fuctionality.
I hope it will be helpful :) Any comments are welcome :)

http://java.dzone.com/articles/image-upload-using-tinymce




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



Re: Create cookie before redirect

2010-04-02 Thread Pawel Koziorowski
Hi!
I slightly customized your code and it works fine. After redirecting I
checked http://localhost:8084/WicketTest/ (where is the code) domain
for CustomerCookie cookie and it existed and every time I click submit
a new cookie is added.

public class Index extends WebPage {

public Index() {
Form loginForm = new StatelessForm(loginForm) {

@Override
protected void onSubmit() {
try {
Customer authenticatedCustomer =
authenticateByLogin(getFormFieldValue(username),
getFormFieldValue(password));

getWebRequestCycle().getWebResponse().addCookie(new
CustomerCookie(authenticatedCustomer, Domain));
getPage().getResponse().redirect(http://google.pl;);
} catch (Exception e) {

}
}

protected String getFormFieldValue(String field) {
return get(field).getDefaultModelObjectAsString();
}

private Customer authenticateByLogin(String
formFieldValue, String formFieldValue0) {
return new Customer();
}
};

TextFieldString user = new TextFieldString(username, new
ModelString());
PasswordTextField pass = new PasswordTextField(password, new
ModelString());
loginForm.add(user);
loginForm.add(pass);
add(loginForm);

}
}

public class CustomerCookie extends Cookie{

private Customer customer;
private String domainName;

public CustomerCookie(Customer customer, String domainName) {
super(customer.toString(), domainName);
this.customer = customer;
this.domainName = domainName;
}
}

public class Customer {

}


2010/4/1 Gustavo Henrique gustavo...@gmail.com:
 Hi!
 I need to create a cookie and redirect to page in other app, but when I try
 redirect the cookie is not send in response:

 Form loginForm = new StatelessForm(loginForm) {
      protected void onSubmit() {
          try {
              Customer authenticatedCustomer =
 customerAuthentication.authenticateByLogin( getFormFieldValue(username),
 getFormFieldValue(password));
              getWebRequestCycle().getWebResponse().addCookie( new
 CustomerCookie( authenticatedCustomer, getDomainName() ) );
              getPage().getResponse().redirect(http://domain.com/myapp;);
          } catch(CustomerAuthenticationException e) {
              add( new Label(customerAuthenticationFailure,
 getString(customerAuthenticationFailure)));
          }
      }

      protected String getFormFieldValue(String field) {
          return get(field).getModelObjectAsString();
      }
 }


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



RE: Hibernate - OSIV

2010-04-02 Thread Pointbreak
With OSIV every user will have a different hibernate-session, hence a
different hibernate object, so your example would work. But your
approach is wrong. For your example I would make a SurveyResult object
that holds a reference to your hibernate Survey object. Problem solved.
No need to play jiggle with transient properties and object identities
in hibernate.

On Thu, 01 Apr 2010 16:11 -0500, Jeffrey Schneller
jeffrey.schnel...@envisa.com wrote:
 Because the objects have transient properties on them that are set by
 another process.  Basically the object is pulled from the db to create a
 shell/container and the transient properties are filled in at a later
 time and may be different.  Not a great example but, the object is a
 survey and the transient properties are the answers that a user will
 provide.  I want to get the same survey twice but allow the transient
 properties to have different values. If it is the same object, I can't do
 this.
 
 The following setting seems to do the trick.  The problem is that after
 some amount of time, everything locks up.  It appears I am out of db
 connections.
 
 filter
 filter-nameopensessioninview/filter-name
 
 filter-classorg.springframework.orm.hibernate3.support.OpenSessionInViewFilter/filter-class
 init-param
   param-namesingleSession/param-name
   param-valuefalse/param-value
 /init-param
 /filter
 
 -Original Message-
 From: James Carman [mailto:jcar...@carmanconsulting.com] 
 Sent: Thursday, April 01, 2010 4:37 PM
 To: users@wicket.apache.org
 Subject: Re: Hibernate - OSIV
 
 Why do you need different objects?
 
 On Thu, Apr 1, 2010 at 4:25 PM, Jeffrey Schneller
 jeffrey.schnel...@envisa.com wrote:
  So by using the OSIV, I am out of luck?  Any ideas?
 
 
 
  -Original Message-
  From: James Carman [mailto:jcar...@carmanconsulting.com]
  Sent: Thursday, April 01, 2010 3:59 PM
  To: users@wicket.apache.org
  Subject: Re: Hibernate - OSIV
 
  They have to be different sessions.  Hibernate's cache (the first
  level) guarantees that you get the same object for any given entity
  within the same session.
 
  On Thu, Apr 1, 2010 at 3:47 PM, Jeffrey Schneller
  jeffrey.schnel...@envisa.com wrote:
  The issue was the object was being evicted from the Hibernate session.
  getSession().evict(object).  I had forgot that the object was being
  evicted from the session.
 
  If I do not evict the object from the session then lazy loading worked.
  This is more of a Hibernate question but, how can I get unique object
  from a hibernate query for each query and have each object be tied to
  the session?
 
  example:
  select * from  Product where sku = ?
 
  I want to select the same sku but get two different java objects from
  Hibernate so the objects are not the same.
 
  Thanks.
 
 
 
 
  -Original Message-
  From: Josh Chappelle [mailto:jchappe...@4redi.com]
  Sent: Wednesday, March 31, 2010 7:01 PM
  To: users@wicket.apache.org
  Subject: RE: Hibernate - OSIV
 
  What error are you getting?
 
  -Original Message-
  From: Jeffrey Schneller [mailto:jeffrey.schnel...@envisa.com]
  Sent: Wednesday, March 31, 2010 4:47 PM
  To: users@wicket.apache.org
  Subject: Hibernate - OSIV
 
  I think I have the OSIV filter setup correctly but I can't access any
  lazy
  loaded properties of my objects.  I am not even between requests when
  this
  is happening.  Does anyone have any ideas?  I can't seem to figure this
  out.
  I have looked at OSIV in Spring and OSIV in Wicket.  I can't seem to
  find
  any examples that will help me to determine the problem.  I have
  included
  all the code and xml configuration that I believe is relevant.  Any help
  would be appreciated.  Also a clean example of how to setup Spring +
  Hibernate OSIV in the wiki would be a big help.
 
 
 
 
 
 
  -
  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
 
 
  -
  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
 
 
 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org
 

-
To unsubscribe, e-mail: 

Wicket GAE performance

2010-04-02 Thread Alejandro
Hi all,

  I've been actively using wicket on GAE for quite a lot of months and I
love it, but I've quite serious performance problems. I already checked all
the advices to speed up the performance but still is quite slow specially
for some requests or opening a bookmarkable page. I don't know what to do, I
use DataView, that it's quite performant, LoadableDetachableModels
everywhere, session is ok in size, so I don't know if there is something I
can tune on the RequestCycle servlet?

  Thanks!


Wicket GAE performance

2010-04-02 Thread Ian Marshall

Hello there,

I delegate the construction of my singleton PersistenceManagerFactory (PMF)
(for data exchange with the datastore) to a queued task, since this
operation can take a few seconds. This way, my home page can show without
waiting for PMF construction to be complete.

I know that the first request to a GAE server will require the starting of a
new JVM (and Wicket application instance) and can take many seconds to be
served. If a Wicket application instance receives no request for a while
then the JVM can be shut down. I think that stuff may be serialised to
persistent storage since data in my Wicket sessions survives such JVM
shut-downs. Anyway, I know that some people create cron jobs or queued tasks
to poke the web application regularly, in order to stop the JVM shutting
down and to maintain the fast serving of web pages.

Is this any help?


intmanch wrote:
 
 I've been actively using wicket on GAE for quite a lot of months and I
 love it, but I've quite serious performance problems. I already checked
 all
 the advices to speed up the performance but still is quite slow specially
 for some requests or opening a bookmarkable page.
 
-- 
View this message in context: 
http://old.nabble.com/Wicket-GAE-performance-tp28118591p28119597.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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



Properties of model are set to NULL even though we have setRequired set to true

2010-04-02 Thread Wayne Pope
Hi,

we've got several examples in our logs of properties of the model
being set to null even though the textfield is set to required.
I have NO idea how on earth this can happen - its just doesn't make
sense - and its really frustrating me!!

here's an example:

Caused by: java.lang.NullPointerException
at org.apache.commons.codec.digest.DigestUtils.md5(DigestUtils.java:86)
at 
org.apache.commons.codec.digest.DigestUtils.md5Hex(DigestUtils.java:108)
at 
hub.app.wicket.admin.ChangePasswordPage$1.onSubmit(ChangePasswordPage.java:49)
at 
org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1518)
...


 FormUser form = new FormUser(form, new
CompoundPropertyModelUser(new HibernateEntityModelUser(User.class,
u.getId( {
@Override
protected void onSubmit() {
User u = getModelObject();


u.setPassword(DigestUtils.md5Hex(u.getPassword());
userDAO.save(u);

setRedirect(true);

setResponsePage(HubApplication.get().getHomePage());
}

};
form.add(new Label(email));
PasswordTextField password = new PasswordTextField(password);
form.add(password);
PasswordTextField repeatPassword = new 
PasswordTextField(repeatPassword);
repeatPassword.setModel(password.getModel());
form.add(repeatPassword);

form.add(new EqualPasswordInputValidator(password, 
repeatPassword));
form.add(new SubmitLink(submitLink));
add(form);


This is just one example - we see elsewhere in the logs sometimes a
textfield that is setrequired(true) ends up nullpointering somewhere
when saving the object.

What could do this?

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



Re: DynamicWizards and Forms

2010-04-02 Thread Jeremy Thomerson
have you looked at the wizard examples in the wicket-examples package?
http://www.wicket-library.com/wicket-examples/

--
Jeremy Thomerson
http://www.wickettraining.com



On Thu, Apr 1, 2010 at 8:49 AM, Sumit Raja sumitr...@gmail.com wrote:

 Hello,
 I am trying to get a dynamic wizard to work with a series of forms. I
 have the following flow:
 (1) Select document type - (2) if document type has embedded audio
 provide an upload form otherwise skip - (3) Document editing form.

 In next() of step 1 I am creating a new Panel with a form of either
 upload or of document editing based on doc type. The odd thing is that
 the submit on the form for step 2/3 seems to get called when next is
 clicked on (1) but before the step (2 or 3) is displayed.

 Looking through the code the if appears that the next() method gets
 called before the actual form processing is performed meaning that the
 form on the next step gets processed as well as the last step. In
 delegateSubmit(), formToProcess.visitChildren seems to be the actual
 place that the next step from gets submitted, before the previous step
 processing is complete.

 What is the correct way to structure a Dynamic wizard when each step
 has nested forms to prevent the visitor submitting the form on the
 next step as well?

 Thanks

 Sumit

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




CookieValuePersister and addOrReplace

2010-04-02 Thread Nikita Tovstoles
Hi,

We have a TextField whose object value we'd like to populate from a Cookie
using CookieValuePersister. Things work fine (persister.save and .load) when
the input is added to the form at Form's construction time. However, in
cases when the input's added to the form using addOrReplace during form's
onBeforeRender, the cookie value is not applied to the input.

That appears to be the case because in
Page.renderPage() setFormComponentValuesFromCookies() is called
*before *prepareForRender()
(which ultimately calls onBeforeRender()).

So, is the bottom line that CookieValuePersister currently cannot be used
when input's added via addOrReplace?

If so, seems like it'd be easy to add if there was a componentAdded callback
on Form:

if(componentAdded.isPersistent())
{
this.getPersister().load(componentAdded);
}


What about an onInitialRender method ?

2010-04-02 Thread Joseph Pachod
hi

The other day, I was busy creating reusable components. To make them safe, I 
used what I believe is a wicket good practices: adding the components in 
onBeforeRender.

In fact, it's not just in onBeforeRender, it's rather :
@Override
protected void onBeforeRender() {
if(!hasBeenRendered()){
// actual code
}
super.onBeforeRender();
}

having done this stuff repeatedly, I felt a bit annoyed but these many
if(!hasBeenRendered()) and the brackets/indentations it brings. 
Furthermore, on the few occasions I really needed something done on each 
onBeforeRender, it brought clutter to the code.
Last but not least, recently, I was helping a wicket beginner and explaining 
this onBeforeRender/if(!hasBeenRendered) wasn't the best moment I had.

As such, I started to wonder if a simple onInitialRender method (or similarly 
named) could be created ? It would run once and only once before the first 
onBeforeRender. 

onBeforeRender would then return to what it should really mean (but still have 
this handy hasBeenRendered() method just in case). 

In the end, it's trivial but would save a few keystrokes and bring some clarity.

What do you think of that ?

thanks in advance
joseph

Re: What about an onInitialRender method ?

2010-04-02 Thread Igor Vaynberg
from Component.java in 1.5 (trunk)

/**
 * Callback method invoked after the component was added to its
parent AND you can walk up the
 * hierarchy up until the Page. That is, all parents must be have
been added to their parents as
 * well. Add this point in time {...@link #getMarkup() getMarkup} is
guaranteed to be available.
 * p
 * This method is guaranteed to called only once
 * /p
 * p
 * If you don't like constructors to initialize your component, this
is the method to use.
 * /p
 */
protected void onInitialize()
{
}

-igor

On Fri, Apr 2, 2010 at 2:03 PM, Joseph Pachod
josephpac...@thomas-daily.de wrote:
 hi

 The other day, I was busy creating reusable components. To make them safe, 
 I used what I believe is a wicket good practices: adding the components in 
 onBeforeRender.

 In fact, it's not just in onBeforeRender, it's rather :
       �...@override
        protected void onBeforeRender() {
            if(!hasBeenRendered()){
                // actual code
            }
            super.onBeforeRender();
        }

 having done this stuff repeatedly, I felt a bit annoyed but these many    
 if(!hasBeenRendered()) and the brackets/indentations it brings.
 Furthermore, on the few occasions I really needed something done on each 
 onBeforeRender, it brought clutter to the code.
 Last but not least, recently, I was helping a wicket beginner and explaining 
 this onBeforeRender/if(!hasBeenRendered) wasn't the best moment I had.

 As such, I started to wonder if a simple onInitialRender method (or 
 similarly named) could be created ? It would run once and only once before 
 the first onBeforeRender.

 onBeforeRender would then return to what it should really mean (but still 
 have this handy hasBeenRendered() method just in case).

 In the end, it's trivial but would save a few keystrokes and bring some 
 clarity.

 What do you think of that ?

 thanks in advance
 joseph

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



Wicket GAE performance

2010-04-02 Thread Ian Marshall

A quick afternote: in my previous post, I assumed that you were using
persistence via JDO code (using PMF).

I don't know how long it takes to construct any equivalent datastore
connection using JPA or the GAE/J persistence API.
-- 
View this message in context: 
http://old.nabble.com/Wicket-GAE-performance-tp28118591p28122983.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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



Re: What about an onInitialRender method ?

2010-04-02 Thread Joseph Pachod
Thanks a lot, glad to know that :)

Yet, I should have figured it out by myself. Next time I'll look directly at 
the source rather than doing a bad nabble search. 

++
joseph



  _  

From: Igor Vaynberg [mailto:igor.vaynb...@gmail.com]
To: users@wicket.apache.org
Sent: Fri, 02 Apr 2010 23:09:27 +0200
Subject: Re: What about an onInitialRender method ?

from Component.java in 1.5 (trunk)
  
   /**
* Callback method invoked after the component was added to its
  parent AND you can walk up the
* hierarchy up until the Page. That is, all parents must be have
  been added to their parents as
* well. Add this point in time {...@link #getMarkup() getMarkup} is
  guaranteed to be available.
* p
* This method is guaranteed to called only once
* /p
* p
* If you don't like constructors to initialize your component, this
  is the method to use.
* /p
*/
   protected void onInitialize()
   {
   }
  
  -igor
  
  On Fri, Apr 2, 2010 at 2:03 PM, Joseph Pachod
  josephpac...@thomas-daily.de wrote:
   hi
  
   The other day, I was busy creating reusable components. To make them 
safe, I used what I believe is a wicket good practices: adding the components 
in onBeforeRender.
  
   In fact, it's not just in onBeforeRender, it's rather :
  @Override
  protected void onBeforeRender() {
  if(!hasBeenRendered()){
  // actual code
  }
  super.onBeforeRender();
  }
  
   having done this stuff repeatedly, I felt a bit annoyed but these many
if(!hasBeenRendered()) and the brackets/indentations it brings.
   Furthermore, on the few occasions I really needed something done on each 
onBeforeRender, it brought clutter to the code.
   Last but not least, recently, I was helping a wicket beginner and 
explaining this onBeforeRender/if(!hasBeenRendered) wasn't the best moment I 
had.
  
   As such, I started to wonder if a simple onInitialRender method (or 
similarly named) could be created ? It would run once and only once before the 
first onBeforeRender.
  
   onBeforeRender would then return to what it should really mean (but still 
have this handy hasBeenRendered() method just in case).
  
   In the end, it's trivial but would save a few keystrokes and bring some 
clarity.
  
   What do you think of that ?
  
   thanks in advance
   joseph
  
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
  


Re: What about an onInitialRender method ?

2010-04-02 Thread mbrictson

Joseph,

Could you elaborate on why adding components in onBeforeRender is safe and
a wicket good practice? I haven't come across this very often in my
projects. Under what circumstances would you recommend this approach?


josephpachod wrote:
 
 hi
 
 The other day, I was busy creating reusable components. To make them
 safe, I used what I believe is a wicket good practices: adding the
 components in onBeforeRender.
 
 In fact, it's not just in onBeforeRender, it's rather :
 @Override
 protected void onBeforeRender() {
 if(!hasBeenRendered()){
 // actual code
 }
 super.onBeforeRender();
 }
 
 having done this stuff repeatedly, I felt a bit annoyed but these many   
 if(!hasBeenRendered()) and the brackets/indentations it brings. 
 Furthermore, on the few occasions I really needed something done on each
 onBeforeRender, it brought clutter to the code.
 Last but not least, recently, I was helping a wicket beginner and
 explaining this onBeforeRender/if(!hasBeenRendered) wasn't the best
 moment I had.
 
 As such, I started to wonder if a simple onInitialRender method (or
 similarly named) could be created ? It would run once and only once before
 the first onBeforeRender. 
 
 onBeforeRender would then return to what it should really mean (but still
 have this handy hasBeenRendered() method just in case). 
 
 In the end, it's trivial but would save a few keystrokes and bring some
 clarity.
 
 What do you think of that ?
 
 thanks in advance
 joseph
 

-- 
View this message in context: 
http://old.nabble.com/What-about-an-onInitialRender-method---tp28122954p28123309.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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



Re: What about an onInitialRender method ?

2010-04-02 Thread Igor Vaynberg
one usecase is when you want the user to be able to change which
components will be created.

this is bad:

class mycomponent extends panel {
  public mycomponent(string id) { add(newCounter(counter)); }
  protected Component newCounter(String id) { return new Label(id, ); }
}

because you are calling an overridable method from constructor, so
instead the call to newcounter can look like this

class mycomponent extends panel {
  protected void onbeforerender() {
if (get(counter)==null) {
  add(newCounter(counter);
 }
 super.onbeforerender();
   }
  protected Component newCounter(String id) { return new Label(id, ); }
}

or with 1.5

class mycomponent extends panel {
  protected void onInitialize() {
  super.onInitialize();
  add(newCounter(counter);
   }
  protected Component newCounter(String id) { return new Label(id, ); }
}

-igor

On Fri, Apr 2, 2010 at 2:56 PM, mbrictson m...@55minutes.com wrote:

 Joseph,

 Could you elaborate on why adding components in onBeforeRender is safe and
 a wicket good practice? I haven't come across this very often in my
 projects. Under what circumstances would you recommend this approach?


 josephpachod wrote:

 hi

 The other day, I was busy creating reusable components. To make them
 safe, I used what I believe is a wicket good practices: adding the
 components in onBeforeRender.

 In fact, it's not just in onBeforeRender, it's rather :
         @Override
         protected void onBeforeRender() {
             if(!hasBeenRendered()){
                 // actual code
             }
             super.onBeforeRender();
         }

 having done this stuff repeatedly, I felt a bit annoyed but these many   
 if(!hasBeenRendered()) and the brackets/indentations it brings.
 Furthermore, on the few occasions I really needed something done on each
 onBeforeRender, it brought clutter to the code.
 Last but not least, recently, I was helping a wicket beginner and
 explaining this onBeforeRender/if(!hasBeenRendered) wasn't the best
 moment I had.

 As such, I started to wonder if a simple onInitialRender method (or
 similarly named) could be created ? It would run once and only once before
 the first onBeforeRender.

 onBeforeRender would then return to what it should really mean (but still
 have this handy hasBeenRendered() method just in case).

 In the end, it's trivial but would save a few keystrokes and bring some
 clarity.

 What do you think of that ?

 thanks in advance
 joseph


 --
 View this message in context: 
 http://old.nabble.com/What-about-an-onInitialRender-method---tp28122954p28123309.html
 Sent from the Wicket - User mailing list archive at Nabble.com.


 -
 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: What about an onInitialRender method ?

2010-04-02 Thread mbrictson

Good example. Thanks for clarifying.


igor.vaynberg wrote:
 
 one usecase is when you want the user to be able to change which
 components will be created.
 
 this is bad:
 
 class mycomponent extends panel {
   public mycomponent(string id) { add(newCounter(counter)); }
   protected Component newCounter(String id) { return new Label(id, );
 }
 }
 
 because you are calling an overridable method from constructor
 

-- 
View this message in context: 
http://old.nabble.com/What-about-an-onInitialRender-method---tp28122954p28123955.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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