render function doesn't exist in play framework 2.0.2? - java

I downloaded and installed play framework 2.0.2 and then created a project. I eclipsified the project and opened it in eclipse.
I have a class called Application which extends Controller class. In most examples around the web, I see controllers like the following.
public class Application extends Controller {
public static void index() {
render(arg0,arg1,...);
}
public static void tasks() {
render(arg0,arg1,...);
}
public static void newTask() {
render(arg0,arg1,...);
}
public static void deleteTask(Long id) {
render(arg0,arg1,...);
}
}
However in my default application, I can only do the following. I don't know how to do the previous one.
public class Application extends Controller {
public static Result index() {
return ok("Hello World!");
}
public static Result tasks() {
return ok(indexabc.render("hello world"));
}
public static Result newTask() {
return TODO;
}
public static Result deleteTask(Long id) {
return TODO;
}
}
In my code when I try to replace "Result" return type with "void", there is no problem. However, when I want to call "render()" method with some parameters, that method doesn't exist. I can't find a way for how to call render function.

The examples you are seeing around the Web are for Play 1.x, and the version you have got in your Controller is for Play 2.x.
Play 1 used render(), play 2 returns a Result object, which is created from calling the ok() method or a number of other methods.
You have 2 options at this point. Download Play 1.2.5 (current stable release) and use the examples you have found, or use the Play 2.x documentation and search for Play 2.x examples.

Related

Using implement an AndroidJavaClass in unity

I have a java object that gets a listener object as a parameter. This listener should implement a certain java abstract class.
I'm trying to prevent writing this in java, because I use an SDK that comes in a jar file, and to call a jar file from a java file, I'll need to create one jar file that includes them both (see Unity3D with multiple jars (android jar + pure java lib))
This answer explains my error but doesn't give a solution.
AndroidJavaProxy is not an interface
I'll try to be more detailed:
I've got the Listener class (which is inside the jar file):
public abstract class AttachCallback {
public AttachCallback();
public void onAttached(Sdk sdk);
}
My c# code is currently (and doesn't work):
public class AttachCallback : AndroidJavaProxy
{
public AttachCallback() : base("com.example.AttachCallback")
{
}
public void onAttached(AndroidJavaObject sdk)
{
Debug.Log("-----Attached------");
}
}
Currently, I get java.lang.IllegalArgumentException: com.example.AttachCallback is not an interface
So, is there a way to do this?
Thanks in advance,
Chaim
First: read this article. Android Java Proxy can implement only interfaces. So you should create interface in java. Something like:
public interface IAttachable
{
public void onAttached(Sdk sdk);
}
In your AttachCallback class you add this interface like:
public abstract class AttachCallback implements IAttachable {
public IAttachable unityCallback;
public void onAttached(String sdk)
{
unityCallback.onAttached(sdk);
}
}
Then in your unity class, create JavaProxy
public class AttachCallback : AndroidJavaProxy
{
public AttachCallback() : base("com.example.IAttachable")
{
}
public void onAttached(AndroidJavaObject sdk)
{
Debug.Log("-----Attached------");
}
}
For attaching your Unity Proxy you should pass your AttachCallback to java, something like:
public void AddAttachToJava()
{
AttachCallback callback = new AttachCallback();
//Passing to activity, but you can do whatever you want
using (AndroidJavaClass javaClass = new AndroidJavaClass("your activity class name"))
{
using (AndroidJavaObject activity = javaClass.GetStatic<AndroidJavaObject>("mContext"))
{
activity.Call("attachUnityCallback", callback);
}
}
}
Your java method in activity should look like this:
public void attachUnityCallback(IAttachable attachable)
{
// if AttachCallback is created
attachCallback.unityCallback = attachable;
attachCallback.onAttached(sdk);
}

Hibernate Search: what is the purpose of static block calling Version#touch()

I'm looking into a source code of Hibernate Search and stumbled into a piece of code which I don't really understand.
There is a static block calling a static method of org.hibernate.search.engine.Version class. I suspect it might be related to JIT but not sure how.
Could you please explain?
public class ImmutableSearchFactory implements ExtendedSearchIntegratorWithShareableState, WorkerBuildContext {
static {
Version.touch();
}
Version class:
public final class Version {
private Version() {
//now allowed
}
public static String getVersionString() {
return Version.class.getPackage().getImplementationVersion();
}
static {
LoggerFactory.make( MethodHandles.lookup() ).version( getVersionString() );
}
public static void touch() {
}
}
Here is the link to GihHub
If the Version class was already loaded, Version.touch(); won't do anything.
If the Version class was not loaded, Version.touch(); will trigger the loading, which in turn will trigger the execution of the following block of static code within the Version class:
static {
LoggerFactory.make( MethodHandles.lookup() ).version( getVersionString() );
}
... which will log the Hibernate Search version.
So the call to Version.touch(); is only there to make sure the Hibernate Search version is logged before Hibernate Search boots.

GWT Interface woes : Breaking on exception: TypeError: Cannot read property 'getRestWrapper' of undefined

I am writing a GWT app using Libgdx & having some difficulties loading the correct rest library at runtime.
In my core gradle project, I have defined a "RestWrapper" Interface that grants access to platform specific REST functions (in the case of GWT, RestyGWT). When the HTML5 launcher is run, it passes it's implementation to the LibGDX game class in the Core Project.
However when the HTML5 Project is run this error is raised by the compiled JS:
Breaking on exception: TypeError: Cannot read property 'getRestWrapper' of undefined
The issue appears to be with the first interface (PlatformWrapper).
I understand the GWT compiler is a bit ham-fisted when it comes to interfaces, Should I be taking a different approach to running GWT specific code from my core project?
Calling code (In core Project:)
UserSessionToken token =client.getPlatform().getRestWrapper().getRestLogin().attemptLogin(userNameBox.getText(),passwordBox.getText());
Interfaces (In core Project):
PlaformWrapper
public interface PlatformWrapper {
public RestWrapper getRestWrapper();....
RestWrapper
/* Platform independent wrapper for REST services */
public interface RestWrapper {
public RestLogin getRestLogin();....
Implementations (In HTML5 Project):
PlatformWrapper (Top level)
public class GWTWrapper implements PlatformWrapper {
public RestWrapper gwtRestWrapper;
public GWTWrapper(){
gwtRestWrapper = new GWTRestWrapper();
}
#Override
public RestWrapper getRestWrapper() {
return gwtRestWrapper;
}
GWTRestWrapper:
public class GWTRestWrapper implements RestWrapper {
public RestLogin restLogin;
public RestPortal restPortal;
public RestRegister restRegister;
public GWTRestWrapper(){
restLogin = new GWTRestLogin(); //GWTRest Logic
restRegister = new GWTRestRegister();
restPortal = new GWTRestPortal();
}
#Override
public RestLogin getRestLogin() {
return restLogin;
}
Cheers.
Working change:
public ApplicationListener getApplicationListener () {
setLoadingListener(new LoadingListener(){
#Override
public void beforeSetup() {
// TODO Auto-generated method stub
}
#Override
public void afterSetup() {
// TODO Auto-generated method stub
wrapper = new GWTWrapper();
client.setPlatform(wrapper);
}
});
return client;

How to use JUnit4TestAdapter with objects

I am trying to write a test suite using JUnit4 by relying on JUnit4TestAdapter. Having a look at the code of this class I saw that it only works with a Class as input. I would like to build a test class and set a parameter on it before running it with my TestSuite. Unfortunately, Junit4TestAdapter is building the test by using reflection (not 100% sure about the mechanism behind it), which means that I cannot change my test class on runtime.
Has anybody done anything similar before? Is there any possible workaround to this issue? Thanks for your help!
public class SimpleTest {
#Test
public void testBasic() {
TemplateTester tester = new TemplateTester();
ActionIconsTest test = new ActionIconsTest();
test.setParameter("New Param Value");
tester.addTests(test);
tester.run();
}
}
/////
public class TemplateTester {
private TestSuite suite;
public TemplateTester() {
suite = new TestSuite();
}
public void addTests(TemplateTest... tests) {
for (TemplateTest test : tests) {
suite.addTest(new JUnit4TestAdapter(test.getClass()));
}
}
public void run() {
suite.run(new TestResult());
}
}
/////
public interface TemplateTest {
}
/////
public class ActionIconsTest extends BaseTestStrategy implements TemplateTest {
#Test
public void icons() {
//Test logic here
}
public void navigateToTestPage() {
//Here I need the parameter
}
}
/////
public abstract class BaseTestStrategy {
protected String parameter;
#Before
public void init() {
navigateToTestPage();
}
public abstract void navigateToTestPage();
public void setParameter(String parameter) {
this.parameter = parameter;
}
}
I am trying to test a web application with Selenium. The way I want to test is by splitting the functionality, e.g., I want to test the available icons (ActionIconsTest), then I'd like to test other parts like buttons, etc.
The idea behind this is to have a better categorization of the functionality available in certain screen. This is quite coupled with the way we are currently developing our web app.
With this in mind, TemplateTest is just an interface implemented by the different kind of tests (ActionIconTest, ButtonTest, etc) available in my system.
TemplateTester is a Junit suite test with all the different tests that implement the interface TemplateTest.
The reason for this question is because I was trying to implement a Strategy pattern and then realized of the inconvenient of passing a class to Junit4TestAdapter in runtime.
Well, taking in account that JUNIT needs your tester's Class object as an object factory (so he can create several instances of your tester), I can only suggest you pass parameters to your tester through System Properties.
Moreover, it's the recommended way of passing parameters: http://junit.org/faq.html#running_7

Android: working with interface and WeakHashMap

After a whole night spent in test (without any luck) I need some support with my interface.
I'm working directly on the Android frameworks and I created a class that works as a Binder with a WeakHashMap to control the callbacks.
Here is the code:
MyCallback:
public interface MyCallback {
public void fire();
}
MyBinder:
public static WeakHashMap<String, MyCallback> mCallbacks =
new WeakHashMap<String, MyCallback>();
public static void setup(MyCallback callback) {
if(mCallbacks.get(callback.getClass().getName()) == null) {
mCallbacks.put(callback.getClass().getName(), callback);
}
}
public static void letsgo() {
Log.d("size", " " + mCallbacks.size()); // IMPORTANT
for (MyCallback cb : mCallbacks.values()) {
cb.fire();
}
}
These 2 classes are written into frameworks so I created 2 test applications with a simple class that implements my interface:
public class FirstApp implements MyCallback {
public FirstApp() {
MyBinder.setup(this);
}
#Override
public void fire() {
Log.d("app1", "fired");
}
}
public class SecondApp implements MyCallback {
public SecondApp() {
MyBinder.setup(this);
}
#Override
public void fire() {
Log.d("app2", "fired");
}
}
Ok at this point I made another class (all these 3 classes, so the 2 that implements the interface and the following one are written into different packages)
In this third class i just call: MyBinder.letsgo();
The issue I'm facing, and that I'm trying to solve since... 8/9 hours is that: If i run letsgo() on the third pack the logs shown 0 for the callbacks WeakHashMap size. if i run letsgo() on the second package it works but it only fires the callback in the same package. the same if i run it on the first package.
I tried also with HashMap instead of WeakHashMap since i red that objects must be referenced but without any luck. I wonder if someone can help me and let me go sleep :D Thanks!

Categories