I saw a few questions about this topic, but none answer the part I am stuck on. By the way, based on the issues people are running into, I might suggest giving a default java implementation of the TemplatesPlugin after all.
The problem I have, is that I copied the two needed views from SecureSocial to my views folder, and changed the RequestHeader as others have noted to: play.api.mvc.RequestHeader and now I am getting:
ambiguous implicit values: both method requestHeader in object PlayMagicForJava of type => play.api.mvc.RequestHeader and value request of type play.api.mvc.RequestHeader match expected type play.api.mvc.RequestHeader
Version: Play-2.1.1, Java 7, SecureSocial from Master.
EDIT:
Play Compile:
[error] C:\Java\AwsConsole\app\views\secure\login.scala.html:41: ambiguous impli
cit values:
[error] both method requestHeader in object PlayMagicForJava of type => play.ap
i.mvc.RequestHeader
[error] and value request of type play.api.mvc.RequestHeader
[error] match expected type play.api.mvc.RequestHeader
[error] #provider(p.id)
[error] ^
[error] C:\Java\AwsConsole\app\views\secure\provider.scala.html:20: ambiguous im
plicit values:
[error] both method requestHeader in object PlayMagicForJava of type => play.ap
i.mvc.RequestHeader
[error] and value request of type play.api.mvc.RequestHeader
[error] match expected type play.api.mvc.RequestHeader
[error] <form action = "#securesocial.core.providers.utils.Route
sHelper.authenticateByPost("userpass").absoluteURL(IdentityProvider.sslEnabled)"
[error]
^
[error] two errors found
[error] (compile:compile) Compilation failed
Browsing after Play Run instead:
Internal server error, for (GET) [/] ->
sbt.PlayExceptions$CompilationException: Compilation error[ambiguous implicit va
lues:
both method requestHeader in object PlayMagicForJava of type => play.api.mvc.Re
questHeader
and value request of type play.api.mvc.RequestHeader
match expected type play.api.mvc.RequestHeader]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun
$apply$16.apply(PlayReloader.scala:349) ~[na:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun
$apply$16.apply(PlayReloader.scala:349) ~[na:na]
at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(Pl
ayReloader.scala:349) ~[na:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(Pl
ayReloader.scala:346) ~[na:na]
at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
The request must be passed explicitely to the login template, the login template must pass the request explicitely to the provider template and the provider template must specify the request when invoking RoutesHelper.authenticateByPost("userpass").absoluteURL. More detailed:
The java TemplatesPlugin should have this getLoginPage implementation:
#Override
public <A> Html getLoginPage(final play.api.mvc.Request<A> request, final Form<Tuple2<String, String>> form,
final Option<String> msg) {
return views.html.login.render(request, form, msg);
}
The parameters (first line) of login.scala.html should look like this:
#(request: play.api.mvc.RequestHeader, loginForm: play.api.data.Form[(String,String)], errorMsg: Option[String] = None)
Change calls from login.scala.html to the provider template to pass the request explicitely (we'll adjust its parameters in the next step).
login.scala.html line 41, change
#provider(p.id)
to
#provider(request, p.id)
login.scala.html line 55, change
#provider("userpass", Some(loginForm))
to
#provider(request, "userpass", Some(loginForm))
The parameters (first line) of provider.scala.html should take the request as first, explicit parameter:
#(request: play.api.mvc.RequestHeader, providerId: String, loginForm: Option[play.api.data.Form[(String, String)]] = None)
Line 20 of the provider template needs to pass the request (so that the correct method is invoked, otherwise you'll get a RuntimeException: There is no HTTP Context available from here):
<form action = "#securesocial.core.providers.utils.RoutesHelper.authenticateByPost("userpass").absoluteURL(IdentityProvider.sslEnabled)(request)"
This should be all needed changes, if you're using other templates they would have to be adjusted accordingly.
Just to mentiond it: I had changed our java TemplatesPlugin to a scala version (to have it more straight forward).
Related
I'm making an web app using GWT i18n. In this app, I would like to set up a custom property files to support differences from main language. For example I have an en_US locale, but also I would like to have en_US_x_custom support with some redefined property fields (specifications of BCP 47 says that I can use -x tag for private tag support).
Let me show what I have for now:
I have an interface
public interface TestMsg extends Messages {
String value();
}
and few property files:
TestMsg_en_US.properties
TestMsg_en_US_x_custom.properties
In app.gwt.xml, I have this lines
<inherits name="com.google.gwt.i18n.I18N"/>
<inherits name="com.google.gwt.i18n.CldrLocales"/>
<extend-property name="locale" values="en_US"/>
<extend-property name="locale" values="en_US_x_custom"/>
However, the problem is that compilations fails with following messages:
[ERROR] Type com.google.gwt.i18n.client.impl.LocaleInfoImpl_en_US_X-custom could not be referenced because it previously failed to compile with errors:
Tracing compile failure path for type 'com.google.gwt.i18n.client.impl.LocaleInfoImpl_en_US_X-custom'
[ERROR] Errors in 'generated://74EF808C0035420F02374EADB97661B8/com/google/gwt/i18n/client/impl/LocaleInfoImpl_en_US_X-custom.java'
[ERROR] Line 10: Syntax error on token "-", < expected
[ERROR] Line 17: The method getLocaleQueryParam() of type LocaleInfoImpl_en_US_X must override or implement a supertype method
[ERROR] Line 10: The public type LocaleInfoImpl_en_US_X must be defined in its own file
[ERROR] Line 22: The method getDateTimeFormatInfo() of type LocaleInfoImpl_en_US_X must override or implement a supertype method
[ERROR] Line 10: Syntax error, insert "AdditionalBoundList1" to complete TypeParameter1
[ERROR] Line 27: The method getNumberConstants() of type LocaleInfoImpl_en_US_X must override or implement a supertype method
[ERROR] Line 12: The method getLocaleName() of type LocaleInfoImpl_en_US_X must override or implement a supertype method
[ERROR] Errors in 'com/google/gwt/i18n/client/LocaleInfo.java'
[ERROR] Line 37: Rebind result 'com.google.gwt.i18n.client.impl.LocaleInfoImpl_en_US_X-custom' could not be found
How do I get rid of this compilation error? How can I fix this problem?
You can ommit -x part of the locale. Then you can specify the locale as en_US_custom and have property file named TestMsg_en_US_CUSTOM.properties (notice capital letters).
I tried to make the zenTasks tutorial for the play-java framework (I use the current playframework, which is 2.3.2). As it comes to testing and adding fixtures I'm kind of lost!
The docu states that
Edit the conf/test-data.yml file and start to describe a User:
- !!models.User
email: bob#gmail.com
name: Bob
password: secret
...
And I should download a sample (which is in fact a dead link!)
So I tried myself adding more Users like this:
- !!models.User
email: somemail1#example.com
loginName: test1
- !!models.User
email: somemail2#example.com
loginName: test2
If I then try to load it via
Object load = Yaml.load("test-data.yml");
if (load instanceof List){
List list = (List)load;
Ebean.save(list);
} else {
Ebean.save(load);
}
I get the following Exception:
[error] Test ModelsTest.createAndRetrieveUser failed:
java.lang.IllegalArgumentException: This bean is of type [class
java.util.ArrayList] is not enhanced?, took 6.505 sec [error] at
com.avaje.ebeaninternal.server.persist.DefaultPersister.saveRecurse(DefaultPersister.java:270)
[error] at
com.avaje.ebeaninternal.server.persist.DefaultPersister.save(DefaultPersister.java:244)
[error] at
com.avaje.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1610)
[error] at
com.avaje.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1600)
[error] at com.avaje.ebean.Ebean.save(Ebean.java:453) [error]
at ModelsTest.createAndRetrieveUser(ModelsTest.java:18) [error]
...
How Am I supposed to load more than one User (or whatever object I wish) and parse them without exception?
In Ebean class save method is overloaded.
save(Object) - expects parameter which is entity (extends Model, has #Entity annotation)
save(Collection) - expects collection of entities.
Yaml.load function returns objecs which can be:
Entity
List of entities
But if we simply do:
Object load = Yaml.load("test-data.yml");
Ebean.save(load);
then save(Object) method will be called. This is because at compile time compiler doesn't know what exactly will Yaml.load return. So above code will throw exception posted is question when there is more then one user in "test-data.yml" file.
But when we cast the result to List as in code provided by OP then everything works good. save(Collection) method is called and all entities are saved correctly. So the code from question is correct.
I have same problem with loading data from "test-data.yml". But I have found solution for this problem. Here is http://kewool.com/2013/07/bugs-in-play-framework-version-2-1-1-tutorial-fixtures/ solution code. But all Ebean.save methods must be replaced with Ebean.saveAll methods.
I use playframework2.2: try to build a play support project.
in my Build.scala, I want to add play.Project.playJavaSetting:
val main = play.Project(appName, appVersion, appDependencies)
.settings(play.Project.playJavaSettings) //error here
.settings(
resolvers += "webjars" at "http://webjars.github.com/m2",
resolvers += "typesafe" at "http://repo.typesafe.com/typesafe/release"
)
the error is:
[error] F:\git\play-example-form\project\Build.scala:19: overloaded method value
settings with alternatives:
[error] (ss: sbt.Def.Setting[_]*)sbt.Project <and>
[error] => Seq[sbt.Def.Setting[_]]
[error] cannot be applied to (Seq[sbt.Setting[_]])
[error] .settings(play.Project.playJavaSettings)
[error] ^
If I do not add playJavaSetting, it give me error about wrong collection apply, I mean:
val main = play.Project(appName, appVersion, appDependencies)
//.settings(play.Project.playJavaSettings)
and the error is:
[error] required: play.api.data.Form<StudentFormData>,scala.collection.immutab
le.Map<String,Object>,scala.collection.immutable.List<String>,scala.collection.i
mmutable.Map<String,Object>,scala.collection.immutable.Map<String,Object>
[error] found: play.data.Form<StudentFormData>,java.util.Map<String,Boolean>,j
ava.util.List<String>,java.util.Map<String,Boolean>,java.util.Map<String,Boolean
you can see the framework apply the scala.collection.immutable.List instead of play.util.List, If I really want to apply the java collections how to set the environment setting in Build.scala file?
You should change
.settings(play.Project.playJavaSettings)
to
.settings(play.Project.playJavaSettings: _*)
The settings method is declared as def settings(ss: Setting[_]*), which means it takes repeated parameters of type Setting[_]. The play.Project.playJavaSettings is of type Seq[Setting[_]]. To convert one to another Scala has a special type annotation.
If you are interested in details check 4.6.2 Repeated Parameters of The Scala Language Specification
I want to create controller method and parametrize it with Class parameter to call it in routes:
GET /api/res1 controllers.GenericController.index(clazz:Class = Res1.class)
GET /api/res2 controllers.GenericController.index(clazz:Class = Res2.class)
and during compilation play shouts:
[error] /home/../workspace/repo/prototype/conf/routes:26: identifier expected but 'class' found.
[error] /home/../workspace/repo/prototype/conf/routes:26: ')' expected but '}' found.
why '}' ? and how to make my idea work?
Try changing to this:
/api/res1 controllers.GenericController.index(clazz: Class[_] = classOf[full.package.name.Res1])
Works just fine for me.
I want to perform search operations on Google Gauva collections in the GWT application.
Those are working correctly in standalone application.But in GWT they are producing
runtime problems.I'm showing my sample code of onModuleLoad() of EntryPoint class.
Iset the buildpath for both guava-gwt-14.0.1.jar and guava-10.0.jar
public void onModuleLoad() {
List<String> sList=new ArrayList<String>();
sList.add("arun kumar");
sList.add("ashok kumar");
sList.add("ravi kumar");
sList.add("kiran kumar");
sList.add("rama");
sList.add("ram");
sList.add("rama krishna");
sList.add("phani");
sList.add("vikram");
sList.add("veeru");
sList.add("arjun");
sList.add("naresh");
//pattern matching
Collection<String> filterdNamesKumar=Collections2.filter(sList, Predicates.containsPattern("kumar"));
//starts with
Collection<String> filterdNamesRam=Collections2.filter(sList, Predicates.containsPattern("^ram"));
Collection<String> filterdNamesAr=Collections2.filter(sList, Predicates.containsPattern("^ar"));
System.out.println(filterdNamesAr.toString());
System.out.println(filterdNamesKumar.toString());
System.out.println(filterdNamesRam.toString());
Map<String,String> emps=new HashMap<String,String>();
emps.put("emp1","01/02/2013");
emps.put("emp2", "10/12/2013");
emps.put("emp3","20/11/2013");
emps.put("emp4", "25/09/2013");
emps.put("emp5", "15/12/2013");
emps.put("emp6", "20/08/2013");
emps.put("emp7", "02/02/2012");
for(String s:emps.keySet()){
String strDate=emps.get(s);
DateTimeFormat dateFormat=DateTimeFormat.getFormat("dd/MM/yyyy");
Date empDate=dateFormat.parse(strDate);
Date startDate=dateFormat.parse("01/11/2013");
Date endDate=dateFormat.parse("31/12/2013");
Range<Date> range=Ranges.closed(startDate, endDate);
boolean b=range.apply(empDate);
if(b){
Window.alert("date found between boundaries");
}
}
}
error:
[DEBUG] [googlegauva] - Validating newly compiled units
[TRACE] [googlegauva] - Finding entry point classes
[ERROR] [googlegauva] - Errors in 'file:/D:/arun/eclipse_Myna/GoogleGauva/src/com/arun/gauva/client/GoogleGauva.java'
[ERROR] [googlegauva] - Line 57: The method containsPattern(String) is undefined for the type Predicates
[ERROR] [googlegauva] - Line 59: The method containsPattern(String) is undefined for the type Predicates
[ERROR] [googlegauva] - Line 60: The method containsPattern(String) is undefined for the type Predicates
[ERROR] [googlegauva] - Unable to find type 'com.arun.gauva.client.GoogleGauva'
[ERROR] [googlegauva] - Hint: Previous compiler errors may have made this type unavailable
[ERROR] [googlegauva] - Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
[ERROR] [googlegauva] - Failed to load module 'googlegauva' from user agent 'Mozilla/5.0 (Windows NT 6.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1' at 127.0.0.1:52248
[DEBUG] [googlegauva] - Validating newly compiled units
[TRACE] [googlegauva] - Finding entry point classes
[ERROR] [googlegauva] - Errors in 'file:/D:/arun/eclipse_Myna/GoogleGauva/src/com/arun/gauva/client/GoogleGauva.java'
[ERROR] [googlegauva] - Line 57: The method containsPattern(String) is undefined for the type Predicates
[ERROR] [googlegauva] - Line 59: The method containsPattern(String) is undefined for the type Predicates
[ERROR] [googlegauva] - Line 60: The method containsPattern(String) is undefined for the type Predicates
[ERROR] [googlegauva] - Unable to find type 'com.arun.gauva.client.GoogleGauva'
[ERROR] [googlegauva] - Hint: Previous compiler errors may have made this type unavailable
[ERROR] [googlegauva] - Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
[ERROR] [googlegauva] - Failed to load module 'googlegauva' from user agent 'Mozilla/5.0 (Windows NT 6.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1' at 127.0.0.1:52251
Patterns.containsPattern is annotated with #GwtIncompatible which means it's not in guava-gwt.
BTW, you should use the same version for guava-gwt and guava.