I have a Play! framework with two actions which contain redundant code. So I factored this code into a private static
method, but It doesn't work anymore then.
public static void show(long itemId, String listId) {
render(getItem(itemId, listId));
}
private static Item getItem(long itemId, String listId) {
// otherwise duplicate code ...
return item;
}
If I inline the code contained in getItem
into the show
action everything is fine:
// this works
public static void show(long itemId, String listId) {
Item item = // duplicate code ...
render(item);
}
Why can I not call other static methods within a Play! controller?
Solution
Thanks to 'Codemwnci' I've implemented the following solution:
public static void show(long itemId, String listId) {
renderArgs.put("item", getItem(itemId, listId));
render();
}
I prefer renderArgs
because it makes the intention more clear than a local variable.