Mixin is not 100% inheritance

Groovy allows us to simulate multiple inheritance by using @Mixin annotation:

  1.  
  2. class Foo {
  3. def sayFoo(){
  4. "hello from foo"
  5. }
  6. }
  7.  
  8. class Bar {
  9. def sayBar(){
  10. "hello from bar"
  11. }
  12. }
  13.  
  14. @Mixin([Foo, Bar])
  15. class Bas {
  16. }
  17.  
  18. def foo = new Foo()
  19. def bar = new Bar()
  20. def bas = new Bas()
  21.  
  22. assert foo.sayFoo() == bas.sayFoo()
  23. assert bar.sayBar() == bas.sayBar()
  24.  
  25.  

but unfortunately it will only copy methods and properties, and will not provide mixed type, so when you try something like this:

  1.  
  2.  

assertion exception will be throw.

Grails url mapping localization

This is simple "hack" that allows you to internationalize your url in your Grails (1.2.x) application. Lets say that we have application that is provided in two languages: Polish and English. Create ours controller:

  1.  
  2. FooController {
  3. def bar {
  4. }
  5. }
  6.  

In ours locale files (message_pl.properties and message_en.properties) add "locale" param (because grails bug) with code specified for this file (pl, en).

Next step is to create new taglib that will generate internationalized link:

  1.  
  2. class BaseTagLib {
  3. def localizedLink = { attrs, body ->
  4. attrs.mapping = message(code:'locale') + StringUtils.toUpperCaseFristLetter(attrs.mapping)
  5. out << link(attrs, body)
  6. }
  7. }
  8.  

This Taglib doing nothing than add prefix for name of the route. It use util method StringUtils.toUpperCaseFristLetter, that capitalize first letter of provided string:

  1.  
  2. class StringUtils {
  3. static def toUpperCaseFristLetter(String text){
  4. text[0].toUpperCase() + text[1..-1]
  5. }
  6. }
  7.  

Now we can provide url mappings as:

  1.  
  2. class UrlMappings {
  3. static mappings = {
  4. name enGoToFooBar:'/go/to/foo/Bar' {
  5. controller = 'foo'
  6. action = 'bar'
  7. }
  8.  
  9. name plGoToFooBar:'/idz/do/foo/Bar' {
  10. controller = 'foo'
  11. action = 'bar'
  12. }
  13. }
  14. }
  15.  

In ours gsp files we can use it like:

  1.  
  2. <g:localizedLink mapping="goToFooBar"><g:message code="text.goToFooBar" /></g:localizedLink>
  3.  

“Why are you using Fire Fox?” pool

I loved Fire Fox. Really and deeply. But let face the truth, at this moment there are better and faster browsers. I personally use FF because it have one grate feature - Fire Bug. And this is only reason why i don't use Chrome for all the time. So - if you are using Fire Fox - drop your voice.

Frontend / Backend misunderstood

Recently my friend come to me, look in project that I am involved into and said: "uuuu, its wrong - there shouldn't be front-end and back-end packages in your project". It was hard to me to admit that this names were wrong for naming main / administration modules . According to Wikipedia:

In software architecture and software design, the front-end is the part of a software system that interacts directly with the user, and the back-end comprises the components that process the output from the front-end. The separation of software systems into "front-ends" and "back-ends" is an abstraction that serves to keep the different parts of the system separated.

so there is no doubt - front-end and back-end are incorrect in this case.

I used this names because in php Symfony framework they are using this naming convention. Well, we learn whole life.

Ps. Thanks Michal 😉

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.