[2.0] How to render a view, java controller

2,007 views
Skip to first unread message

Daniele Aramu

unread,
Mar 31, 2012, 1:17:48 PM3/31/12
to play-fr...@googlegroups.com

Hi all, I have my controller that has to render the home view only. I can’t figure out to create a result to render my simple html page. No scala, no templates, no hard-coding, only returning my view from the views directory.

 

Regards

 

Daniele

biesior

unread,
Mar 31, 2012, 4:50:33 PM3/31/12
to play-fr...@googlegroups.com
I don't get it... why you just don't render the result ?

public static Result rawcode(){
    return ok(rawview.render());
}

then you can just use rawview.scala.html with ... html code inside (you don't need to use template's tags)

Daniele Aramu

unread,
Apr 1, 2012, 5:10:43 AM4/1/12
to play-fr...@googlegroups.com

That’s right. Therefore I’m experiencing problems using ok(any-of-my-views.render()) because of compilation problems. I work with eclipse and the only view that works is the one created by using “play new my-project-name”. Anyway also the default “return ok(index.render())” give compilation problem in eclipse.

Maybe it’s just a enviroment configuration problem, if anyone can help, it’s much appreciated.

Kind regards

 

Daniele

 

Da: play-fr...@googlegroups.com [mailto:play-fr...@googlegroups.com] Per conto di biesior
Inviato: sabato 31 marzo 2012 22:51
A: play-fr...@googlegroups.com
Oggetto: [play-framework] Re: [2.0] How to render a view, java controller

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/5N41sAanAcMJ.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

biesior

unread,
Apr 1, 2012, 5:32:11 AM4/1/12
to play-fr...@googlegroups.com
ellou' Daniele

Each view is compiled as new class, so make sure, that you have imported new view:

import views.html.any-of-my-views1;
import views.html.any-of-my-views2;


or import all at once:

import views.html.*;

Of course if you started your app in production mode, you have to restart it. In dev mode classes will be hot reloaded.




W dniu sobota, 31 marca 2012, 19:17:48 UTC+2 użytkownik Daniele Aramu napisał:

Daniele Aramu

unread,
Apr 1, 2012, 5:54:57 AM4/1/12
to play-fr...@googlegroups.com

Hi all, there were a compilation problem because of not including the classes_managed directory where scala classes are. Then I expected that play automatically builds my new views, but it does not. So I have to launch the compile command from console for having my scala classes compiled, and that’s really annoying! If anyone can figure out how to tell play to build the classes I’m  working on eclipse please tell.

Kind regards

 

Daniele

 

P.S.: Anyone had the Global class problem that it runs the onStart on every request but when the application come up?

 

Da: play-fr...@googlegroups.com [mailto:play-fr...@googlegroups.com] Per conto di biesior
Inviato: domenica 1 aprile 2012 11:32


A: play-fr...@googlegroups.com
Oggetto: [play-framework] Re: [2.0] How to render a view, java controller

 

ellou' Daniele

--

You received this message because you are subscribed to the Google Groups "play-framework" group.

To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/HQRlJ_NBS8AJ.

Player2.0

unread,
Apr 1, 2012, 11:25:33 AM4/1/12
to play-fr...@googlegroups.com
it doesn't work. It cannot resolve path to my views. 

will_w

unread,
Apr 1, 2012, 5:57:01 PM4/1/12
to play-fr...@googlegroups.com
Did you try the 'play clean' command? Sounds like the issues I was encountering a few days ago.

vorbidan

unread,
Apr 1, 2012, 8:28:38 PM4/1/12
to play-framework
play clean
play eclipsify
play compile

Too bad there is no better way

Kevin Bosman

unread,
Apr 3, 2012, 5:34:33 PM4/3/12
to play-fr...@googlegroups.com
> play clean
> play eclipsify
> play compile
>
> Too bad there is no better way

This works for me with Indigo (ymmv):
Never build in Eclipse - causes too many conflicts and eclipse gets
badly (and permanently) out of sync far too easily, so turn off
autobuild and autorefresh.
Set options in General|Workspace: Auto build - OFF, Refresh with hooks
+ polling OFF, Refresh on access ON
Make sure target/scala-2.9.1/classes_managed is present in referenced
libraries (this gets added by play eclipsify, so it shouldn't be a
problem)

In play type
~run

The "~" forces auto recompilation. So your templates will be compiled
and ready in the classes_managed folder when you need them in eclipse.
Also you can review your changes in your browser almost immediately.
If your changes are not showing in eclipse immediately, refresh the
project node, and the red squiggles should go away.

If eclipse gets badly out of sync, then the best thing to do is to
remove the project from eclipse, delete all the eclipse specific
settings from your project folder (./.settings), then play clean
eclipsify
if you want all library sources included, use play clean eclipsify
with-source=true
Then import your project into your eclipse workspace again.

hth.

Reply all
Reply to author
Forward
0 new messages