I'm trying to get the flash data that has been passed from the controller in the view. In the Play documentation (https://www.playframework.com/documentation/2.8.x/JavaSessionFlash) it says the flash can be get like this:
#flash.get("success").orElse("Welcome!")
However, I'm getting this error when I try to compile the project
[error] .../edit.scala.html:4:3: not found: value flash
[error] #flash.get("test").orElse("No flash!")
[error] ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
I've also tried using #request.flash and it gave the same error.
How can I get the flash or request in the view for Play Framework 2.8. Am I missing some import or something like that?
Since you're using Java you need to pass the request param to the template. At the top of the template file:
#( ... your normal params ...)(implicit request: Http.Request)
Now to get the flash use the request:
#request.flash().getOptional("test")
Related
I generated a simple libGDX project with no dependencies. When I tried to build it as HTML app with Gradle (./gradlew html:dist), I get the following error message:
Tracing compile failure path for type 'xjcl.downgradius.client.HtmlLauncher'
[ERROR] Errors in 'file:/home/jan/Dropbox/py/AndroidStudioProjects/Downgradius_Android/html/src/xjcl/downgradius/client/HtmlLauncher.java'
[ERROR] Line 49: No source code is available for type xjcl.downgradius.DowngradiusGame; did you forget to inherit a required module?
I think the problem is caused by me using Kotlin in this project, and libGDX being intended for Java development. I observed that when I made a new main Game class in Java, that class was found by GWT, but not the Kotlin classes it imports.
I know Kotlin does some re-packaging (for example, if you put funA and funB in file Foo, they will be re-packaged as part of a new FooKt package, I think), but it should be able to find it as
it is declared in the right package (xjcl.downgradius)
it is declared as the only class in its file
I get no IDE warnings about importing it from Java.
I also tried converting Kotlin to Java code but the resulting Java code was full of errors.
Your assumptions are correct. GWT compiler works on Java sources. The error message it gives you is correct: There are no Java source code files to be found, you say it yourself that you used Kotlin.
If you want to use GWT, convert to correct Java source code.
I'm using Play 2.4 (Java version) but I'm also interested in solutions for >2.4. This is my problem. I want to structure the content of my template folder under app/views. So I'd like to create some sub packages under app/views but get compilation errors. Here is, what I've tried so far:
Create new subpackage via eclipse
app/views/mediaViewers
Put a template standardViewer.scala.html in it
app/views/mediaViewers/standardViewer.scala.html
Try to access the template from controller class via
views.mediaViewers.html.standardViewer.render()
Rebuild play project
activator clean; activator clean-files; activator run
When calling the appropriate route I get:
[error] .../Viewers.java:18: package views.mediaViewers.html does not exist
[error] views.mediaViewers.html.standardViewer
[error] ..../Viewers.java:21: package views.mediaViewers.html does not exist
[error] views.mediaViewers.html.standardViewer
[error] .../app/controllers/Viewers.java:24: package views.mediaViewers.html does not exist
...
[error] (compile:compileIncremental) javac returned nonzero exit code
[error] application -
! #765kicfe1 - Internal server error, for (GET) [/] ->
play.sbt.PlayExceptions$CompilationException: Compilation error[package views.mediaViewers.html does not exist]
...
In order to call a view template from the controller you should alwayes prefix the name of the view with "views.html", so the call to standardViewer.scala.html would be :
views.html.mediaViewers.standardViewer
you can verify this if you took a look at the generated files under target/scala-/twirl as indicated in this picture :
project structure
The package path in the controller is wrong! Use this pattern:
`views.html.your-package-goes-here.your-template-goes-here.render()`
Or more concrete:
Try to access the template from controller class via
views.mediaViewers.html.standardViewer.render()
Has to be:
views.html.mediaViewers.standardViewer.render()
I followed the documentation for using app.yaml with Java which claims that this should work and that it will generate web.xml and appengine-web.xml automatically. However, it doesn't seem to work and it doesn't mention which tool will generate the files.
I first tried a mvn clean install which errors out because the .xml files are missing:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.4:war (default-war) on project roger-analytics: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
I then tried to run the local development server:
$ gcloud preview app run app.yaml
ERROR: (gcloud.preview.app.run) An error occurred while parsing file: [/Users/blixt/src/roger-api/module_analytics/app.yaml]
Unexpected attribute 'servlet' for object of type URLMap.
in "/Users/blixt/src/roger-api/module_analytics/app.yaml", line 7, column 12
(I get the same error from dev_appserver.py . by the way)
It appears that app.yaml isn't supported after all. Am I missing something, or was support removed without updating the documentation?
Here's my app.yaml file, which is intended to run as a module in my Google Cloud App Engine project (along with other modules that have Python and Go runtimes):
module: analytics
runtime: java
api_version: 1
handlers:
- url: /*
servlet: im.rgr.roger.RogerAnalytics
login: admin
secure: always
system_properties:
java.util.logging.config.file: WEB-INF/logging.properties
There are several issues at play here. I'll describe various facts that group together to create a constellation of SDK edge-case goodness (this information is current as of SDK 1.9.21):
In order to deploy using the Java SDK's appcfg.sh, you'll need to have app.yaml inside the war/WEB-INF/ folder.
appcfg.py complains Unexpected attribute 'servlet' for object of type URLMap..
gcloud preview app deploy uses appcfg.py (or the same codebase) and therefore also complains in the same manner
So, in conclusion, you'll need to use appcfg.sh
Is java.util.zip.Deflater available in GWT 2.6.0? Do I need to do anything special to be able to use it?
I get this error message currently when trying to compile as part of running Super Dev Mode:
[ERROR] Line 238: No source code is available for type java.util.zip.Deflater; did you forget to inherit a required module?
You can't use java.util.zip.Deflater at client side in GWT application because GWT is unable to compile it into JavaScript.
Read more about GWT library emulation
I am trying to "Mavenize" our existing Commerce solution. However, I am getting a weird error when I try to run mvn compile I get the following error.
[ERROR] /home/user/tmp/IBM/WCDE_ENT70/workspace/WebSphereCommerceServerExtensionsData/ejbModule/org/ecommerce/wcs/changerequest/ChangeRequestAccessBean.java:[347,32] cannot find symbol
[ERROR] symbol : method createAccessBeans(java.util.Collection)
[ERROR] location: class org.ecommerce.wcs.changerequest.ChangeRequestAccessBean
When I check the class it is related to the com.ibm.ivj.ejb.runtime.AbstractEntityAccessBean class which IBM has neglected to include JavaDoc for anywhere. I look into eclipse and it shows me the method in question was correct using code complete, however, it still fails with maven.
I am wondering if it isn't a customisation to the IBM jre (I am not using that for this POC) and if there is no way around it (short of extending the class and reimplementing).
Anyone?
Problem had to do with multiple imports of different versions of the same dependency. Now this has been resolved.