Skip to content

Arch-vile/PropertyNavigation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PropertyNavigation

What

Utility to create property expression by navigating object hierarchy.

Why

So that you dont need to use static strings that contain risk of typos and are easily broken during refactoring.

How

Say you have a Book class that has Author as class variable (accessable by getter) and the Author has a name.

prop(of(Book.class).getAuthor().getName())

Will return string "author.name".

If you want to include the root element in the returned property use:

prop(to(Book.class).getAuthor().getName())

Whic returns string "book.author.name"

Application examples

Wicket:

Use with PropertyModel to have refactor safe property accessors.

Instead of:

add(new Label("myLabel", new PropertyModel(person, "name"));

You can say:

add(new Label("myLabel", new PropertyModel(person, prop(of(Person.class).getName())));

Grails:

Use in the GSP pages to have compile and refactor safe bindings to command objects

Instead of:

<g:textField name="player.name"/>

Use:

<g:textField name="${prop(to(Command.class).player.name))}"/>

Tests

Known issues Wont work for final classes in the middle of the path. E.g. in

prop(on(Person.class).getName().getBytes)

where getName() returns a String which is final.

About

Utlity to provide refactor safe property paths to beans

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages