Summary of ways you can control the request/response flow in play in controllers & actions - scala

Can someone summarize with a very short code snippet (or link to docs) the ways you can control/modify the request/response cycle in play. (scala version if that matters)
So far I know of:
Create a base controller that your other controllers will extend/inherit
Use #Before and #After
Will this work in the latest 2.2.2 version?
Action compositions http://www.playframework.com/documentation/2.0/ScalaActionsComposition
What else is there?

Action Composition: http://www.playframework.com/documentation/2.2.x/ScalaActionsComposition
The Global object: http://www.playframework.com/documentation/2.2.x/ScalaGlobal
Interception with filters or onRouteRequest: http://www.playframework.com/documentation/2.2.x/ScalaInterceptors
Filters vs Action composition: http://www.playframework.com/documentation/2.2.x/ScalaHttpFilters
The method with a base controller looks more like a dirty hack to me. Especially when using Play with Scala (in Java everything looks like a dirty hack :) )

Related

IntelliJ IDEA, Open API - list methods requiring be implemented

I am developing an IntelliJ IDEA plugin which has to generate some project-specific classes in the Java/Scala project. I have a superclass and a few traits to extend. How can I list methods, which I need to implement in a class being created?
I mean the same list that will appear in the 'Implement methods' dialog.
In the source code for the IDEA community version, take a look at the com.intellij.codeInsight.daemon.impl.quickfix.ImplementMethodsFix class for an example of doing this. The chooseMethodsToImplement method ultimately calls com.intellij.codeInsight.generation.OverrideImplementUtil
.showOverrideImplementChooser(...) to get the methods. Also take a look at the com.intellij.codeInsight.generation.OverrideImplementExploreUtil class.

IoC, MVC4 Web API & HttpParameterBinding/ParameterBindingAttribute

I'm using ASP.Net MVC 4 RTM Web API. I have a controller action with a parameter that I'd like to populate via custom model binding. To achieve this, I created a class that derives from System.Web.Http.Controllers.HttpParameterBinding that sets the value of this parameter. I then created an attribute class that derives from System.Web.Http.ParameterBindingAttribute which I use to decorate the parameter on my controller action.
This is all working great, my HttpParameterBinding class is populating the action parameter correctly. The problem I have is that my custom parameter binding class has a dependency that I'd like resolved via my IoC container (Unity). Is there a way to override how Web API creates HttpParameterBinding instances so that I can build up my custom binding class dependency from Unity? I was able to do something similar for a filter attribute by creating a custom filter provider that uses Unity's BuildUp method to populate dependencies, however I'm not seeing anything similar for Web API's HttpParameterBindings.
In general: to use IoC / Unity in the Web API you need to set it up seperately.
Try downloading the nuget package Unity.WebApi and see if that helps!
Take a look at this article: Parameter Binding in WebAPI
It walks through a couple different options from Converters to Binders to BinderProviders. It sounds like you may be able to write a custom ModelBinderProvider which knows how to provide your dependency. If that isn't high enough in the chain you can look at replacing the default IActionValueBinder service. It's a DefaultActionValueBinder instance, which you can extend or simply re-implement.
I also highly recommend downloading the WebAPI source code, as it's been an incredible help for these issues as I've run into them. Here's the WebAPI source code. I recommend downloading it so you can open it in VS for easy navigation.
Feel free to check out FlitBit too (It's very modular, don't let the number of packages scare you off)! I'm working on a WebAPI package for supporting FlitBit, specifically FlitBit.IoC and FlitBit.Dto. I'll add an update if I work out my IoC issue, since it's very similar to yours.

Server-side GWT events; alternative to Vaadin

I'm wondering is there a similar framework like Vaadin built on top of GWT which wraps the original GWT components but with server-side only event handling? (I know that Vaadin is built on top of GWT. I'm looking for an alternative solution.)
Vaadin is nice because of it's precompiled nature. I found compile times with GWT horrific the last time i've worked with it. Also it's a bit easier to maintain security if event handling code runs on the server. It would be nice if the standard GWT could be used in a similar way.
I don't think there is another like vaadin. and vaadin is already server-side..
see this http://vaadin.com/learn for more info
Have you seen this? - http://code.google.com/p/gwteventservice/
For server-side alternative, you might take at a look at ZK too.
Notice that its client side is based on jQuery, not GWT. However, you won't notice it at all since they both are server-side solutions and using pure Java.
Event handlers that you normally deal with are in server-side Java code. Consider this:
final Button testButton = new Button("Test Button");
testButton.addListener(new Button.ClickListener()
{
#Override
public void buttonClick(ClickEvent event)
{
mainWindow.showNotification("I am server-side code!");
}
});
As you said, you need to compile GWT code only when adding a custom component to your code. Vaadin's built in components are already compiled and put in the jar file. Although sometimes your IDE might detect your project as a GWT project and try to compile the widgetsets every time you change the code, when you might want to ask it to ignore.
If you look for alternatives to Vaadin you might have a look at Echo2.

What is the use GWT generator?

I have seen that GWT framework is having generator feature.
In what case we have to use gwt generator option and why it is needed?
Can anyone tell me simply why,what is gwt generator? Done some googling. But not much helpful stuffs...
From this tutorial:
Generators allow the GWT coder to generate Java code at compile time and have it then be compiled along with the rest of the project into JavaScript.
This tutorial uses the example of generating a Map of values at compile time based on a properties file.
I've done GWT development for 3 years now and I've written one generator :) I've written a couple of linkers for experimental purposes so I think they are more common, though still rare. The classic case is where you want to write
X x = GWT.create(X.class)
and have the particular subclass or implementation of X constructed at compile time based on, perhaps, annotations in the provided X class or interface. GWT uses them for things like the CSSResource.
Search for "GWT Generator Experiments" site:development.lombardi.com on google for some info about what I did.
One of the use cases is to mimic reflection on the client side by building a factory class on the fly. I remember answering a question posted by you earlier on how to do this
How to create new instance from class name in gwt?
So i guess you already know the application. What else are you looking for? Can you be precise?
I've started using GWT Generators where I needed Java Reflection. I've documented One of the use cases for using GWT generators here:
http://jpereira.eu/2011/01/30/wheres-my-java-reflection/
Hope it helps.
If you refer to code generator, yes, there will a tool supporting GWT 2.1 code generation. For more details and a quick start, see http://www.springsource.org/roo/start
A general roo intro is here http://blog.springsource.com/2009/05/01/roo-part-1/
Another visual tutorial is at http://www.thescreencast.com/2010/05/how-to-gwt-roo.html
Check out this implementation:
http://samuelschmid.blogspot.com/2012/05/using-generator-for-generic-class.html
You can create new Instances of classes on client with foo.newInstance("fully.qualified.class.name");

GWT Composite best practices

I'm learning GWT and have started to get the hang of it. I'm at the point where my code is getting to be a spaghetti mess so I'm going back and factoring reasonable bits of it out as Composites. The first problem I ran into was that my tool support failed to give the new Composite class an initWidget() method. It did include a default constructor.
For the time being, I've simply filled in my overridden initWidget() method with a call to super(initWidget(w)) My project compiles and runs as expected, though I feel as though I must be missing something.
What should I keep in mind when overriding init and what if anything do i need to place in the constructor. Is there anything else that I need to know or does it just boil down to regular old Java after this?
Clarification - It has occurred to me that there are probably different answers to this question depending on whether you intend to release said Composite classes as part of a library or simply part of your stand-alone app. I in particular have no intention at this time of developing externally useful components (mainly because I'm so green in this particular technology.)
Thanks!
I'm not sure if I understand what you are trying to do. But for all the Composite's I've written I've never overridden the initWidget method. Because Composite itself doesn't need to be initialized with a constructor, i.e. no need to call super() my constructors of widgets extending composite look something like:
public mywidget() {
SomePanel p = new SomePanel();
....
initWidget(p);
}
As a best practice, imo, only the widget extending Composite should call it's 'own' initWidget.
"GWT Conference: Best Practices for Building Libraries" gives a couple of tips. You should also look at the source of GWT and at the source of one of the libraries for GWT (like gwt-ext)
[EDIT] I just saw another option: suco. From the description:
A micro library that helps to maintain your GWT client code clean and modular.