Archive

Posts Tagged ‘tips’

Small Wicket tips

juillet 23, 2010 Laisser un commentaire

[Cet article est également disponible en français.]
In the last weeks, I’ve been doing quite some Wicket work.

Here are some small tips gathered on the way 🙂

  • If you use an AjaxButton, don’t forget to override onError and to add a feedback panel to the target! Indeed, an AjaxButton triggers form validation. And if this fails, then feedback messages should have been created on the way. Having them displayed is kind of handy ;).
  • Know and use Component.setRenderBodyOnly(boolean renderTag).This little method allows to skip the component tag when rendering. Doesn’t sound crazy like that, but comes handy when one has an optional fieldset.
  • FormComponent.updateModel() is only effective if the new model object isn’t equal to the previous one.Indeed, FormComponent.updateModel() calls Component.setDefaultModelObject(), when checks for non equality before setting the new object. Why ? It saves making an extra page version if no change was done. Yet, if your equals isn’t appropriate, this may result in changes not being done for no visible reason. To avoid this, override Component.getModelComparator() and provide an appropriate comparator, like one testing only for same reference equality.

Hopefully it may help someone 🙂

++
joseph

Publicités
Étiquettes : , ,

Petites astuces Wicket

juillet 23, 2010 Laisser un commentaire

[This article is also available in English.]
Ces dernières semaines, j’ai pas mal utilisé Wicket.

Voici quelques petites astuces rencontrées en chemin 🙂

  • Si vous utilisez un AjaxButton, surchargez onError et ajoutez un FeedbackPanel à ce qui sera réaffiché! En effet, un AjaxButton déclenche la validation du formulaire auquel il est rattaché. Et si cette validation échoue, il est fort probable que des FeedbackMessage soient créés en chemin. Il serait dommage de ne pas les afficher ;).
  • Connaissez et utilisez Component.setRenderBodyOnly(boolean renderTag).Cette petit méthode permet de ne pas afficher le tag html auquel le composant est attaché, tout en affichant son contenu. Ca peut paraitre anodin, mais cela s’avère bien pratique lorsqu’on veut afficher de façon optionnel le fieldset entourant un composant.
  • FormComponent.updateModel() n’est effectif que si le nouvel objet rattaché au modèle n’est pas égal au précédent.En effet, FormComponent.updateModel() appelle Component.setDefaultModelObject() avec le nouvel objet. setDefaultModelObject vérifie alors que le nouvel objet ne soit pas égal au précédent. Il fait cela afin d’éviter de créer une version non nécessaire de la page (qui sera ensuite gardée dans la PageMap). Ceci dit, si votre equals() n’est pas approprié, cela peut amener certains changements à ne pas être pris en compte (sans raison évidente). Pour éviter cela, il suffit de surcharger Component.getModelComparator() et de fournir un comparateur correspondant. Par exemple un comparateur ne vérifiant que l’égalité des références.

J’espère que cela pourra aider !

++
joseph

Étiquettes : , ,

(Petite) Astuce wicket : ne pas caster sa classe Application

Salut

Fréquemment, il m’arrive du voir du code wicket tel que

((MyApplication)Application.get()).myApplicationSpecificMethod();

Perso, cela me pique toujours un peu les yeux. Or, il y a tout simple, à savoir définir dans MyApplication quelque chose comme:

public static MyApplication getWebApplication() {
return (MyApplication) Application.get();
}

on peut alors écrire :

MyApplication.getMyApplication().myApplicationSpecificMethod();

Cela peut s’applique également à la Session, pour sûr.

voilà, trois fois rien, clairement, mais un pas de plus vers un code propre. Ca en vaut donc la peine (et ça m’évitera de me répéter sur le forum wicket développez.com, even better ;)).

++
joseph

Étiquettes : , ,

m2eclipse workspace resolution not working ?

janvier 19, 2010 1 commentaire

We have this « fix »:

  • Go to your workspace folder
  • in the folder .metadata/.plugins/org.maven.ide.eclipse, remove all file ending with .container
  • in eclipse, clear all projects
  • hope for the best

For us, it has resolved a nasty issue we had : some projects’ dependencies weren’t resolved locally even if the projects in question were in the workspace.

Hope it helps

++

Étiquettes : , , ,

How we have the development specific code safely out of the way

septembre 12, 2009 2 commentaires

Quite frequently, one has to write some development specific code. For example, at work, we have, when needed, an « application launcher » (named with the application name) and a dev web page, mounted under /dev. This page in turn allows to write shortcuts in the application work flow, in order to access specific page with an ad hoc environment (profile, data…).

However, one quickly wonders how to be sure these classes won’t get in production.

Our solution is linked to m2eclipse. This maven plugin for eclipse has the following behavior : it puts both the main and test source paths in the class path. As such, one can access both the production and test code when running the application from eclipse. This is normally not done by Maven. More precisely, Maven build jars don’t include the test code.

The solution is then really easy : we put our dev. specific code under the test branch, and we are perfectly able to run it all from eclipse. But Maven makes sure none of it will make it into the production jar/code. Double with this application launcher + dev page conventions, it really makes it simple to dig into an application/project. Nice and easy no ?

Étiquettes : , , ,

Defining JavaScript variables…

septembre 3, 2009 Laisser un commentaire

hi

Do you know the difference in JavaScript between these variables declarations :

– myVar = « foo »

– var myVarVar = « foo »

In fact, the first one will have an unlimited scope, and thus accessible from the outer world, whereas the second one will only be accessible at this level and below.

As such, this is why the line « $.fn.myFunction = function(){bla};  » is used to declare new function to the jQuery object.

Similarly, make sure you use « var » in front of your own JavaScript variables to avoid name collisions !

Hope it helps !

++

PS : funny how I’ve plenty of long posts in mind but not yet written (out of laziness/lack of time) while at the same time I’m eager to write small ones on stuff I’ve just discovered… May be I should consider twitter more closely !

PPS : the (french) source of this post : developpez.com

Étiquettes : , ,

m2eclipse tips

août 18, 2009 2 commentaires

Thanks to Maven: The Definitive Guide, I was able to answer some questions I had about m2eclipse as well as learn more of it.

  • When you put a plugin in the build part of the pom, how comes some are running on each source modification and others not ?
    The reason is simple : m2eclipse runs by default the plugins in the process-resources phase. Furthermore, this is set up in the Preferences/Maven part of eclipse (but the settings affects all projects, which was a bit overkill for us)?

  • One can ask m2eclipse to display the projects’ maven version, through Preferences/General/Appearance/Label Decorations and then check « Maven Version Decorator ». Comes handy when having to update different versions of different plugins.

  • Last but not least, the pom editor « Dependency hierarchy » tab is in fact pretty useful :$
    Before I was looking at the « Maven Dependencies » folder to figure out what was there, but in fact this tab displays it nicely.
    Two lists are shown there : « Dependency Hierarchy » and « Resolved dependencies ». The first one allows to figure out what was rejected (and from where in the dependencies), the second one shows what is in.
    A search is available and run on both lists. So if you wonder about spring dependencies issues, just put spring in the search field, and you all artifact ids containing spring are highlighted.

Hope it helps !
++

Étiquettes : , ,
%d blogueurs aiment cette page :