小编adi*_*dis的帖子

使用加密解密字符串

Play Framework 2.0提供了lib Crypto,参见代码:https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/libs/Crypto.scala

所以如果想要签署一个我可以使用的值:

Crypto.sign(username);
Run Code Online (Sandbox Code Playgroud)

但是如何再次解密用户名?有没有方法取消签名解密?或者我在这里遗漏了什么?

playframework-2.0

6
推荐指数
1
解决办法
3135
查看次数

如何使用PlayFramework压缩html

为了提高Scala表单的可读性,我经常使用缩进和新行.但是当我在我的播放应用程序启动并运行时验证HTML时,我看到很多空格和不必要的换行符.有没有为什么要在没有"让我的scala模板不可读"的情况下压缩这个HTML?

谢谢

playframework-2.0

6
推荐指数
1
解决办法
2294
查看次数

资产已定义为对象资产

我正在为Play Subproject功能进行更多扩展测试,如下所述:http://www.playframework.com/documentation/2.0/SBTSubProjects.但是我收到了错误:

Assets is already defined as object Assets
Run Code Online (Sandbox Code Playgroud)

在github上托管的示例应用程序:https://github.com/adis-me/PlayStrap

我已经为我的子项目定义了一个Asset控制器,如下所述:资产控制器描述,即使是主项目,但错误仍然会弹出.我的项目有什么问题?

调节器

package com.company.playstrap.controllers;

import controllers.AssetsBuilder;

public class Assets {

    public static controllers.AssetsBuilder delegate = new AssetsBuilder();

}
Run Code Online (Sandbox Code Playgroud)

路由文件

# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET     /                               com.company.playstrap.controllers.Application.index()

# Include sub projects
-> /common                              common.Routes
-> /admin                               admin.Routes
-> /website                             website.Routes

# Map static resources from the /public folder …
Run Code Online (Sandbox Code Playgroud)

playframework playframework-2.0 playframework-2.1

6
推荐指数
1
解决办法
5328
查看次数

更改 application.conf 运行时?

我想在运行时为我的 Play 项目设置数据库连接。我知道我可以使用以下代码设置属性运行时:

@OnApplicationStart public class Bootstrap extends Job
{
   @Override public void doJob()
   {
     // now set the values in the properties file
     Play.configuration.setProperty("db.driver", dbDriver);
     Play.configuration.setProperty("db.url", dbUrl);
     Play.configuration.setProperty("db.user", dbUsername);
     Play.configuration.setProperty("db.pass", dbPassword);
   }
}
Run Code Online (Sandbox Code Playgroud)

但是当执行上面的代码时,文件实际上并没有改变,我认为只是在内存中。

如何设置数据库属性并强制播放!使用此属性以连接到正确的数据库 onApplicationStart?

谢谢!

更新 2012-01-29

可以通过插件解决。在这个插件中,我必须覆盖 onConfigurationRead()并将属性应用于当时的配置文件。一旦我有时间,我会尝试发布一些代码。

properties playframework

5
推荐指数
1
解决办法
2328
查看次数

从null对象的绑定:RuntimeException:java.lang.reflect.InvocationTargetException

我正在继续学习Play 2.0,我正在使用登录表单.基本上与Zentasks提供的示例项目类似的形式......

我的问题是在数据库中找不到用户时的错误消息,错误发生在以下行:

Form<Login> loginForm = form(Login.class).bindFromRequest();
Run Code Online (Sandbox Code Playgroud)

我的模型看起来像:

@Entity
public class Person extends Model {

@Constraints.Required
public String password;

@Constraints.Required
public String email;

// -- Queries

public static Model.Finder<String, Person> find = new Model.Finder(String.class, Person.class);

/**
 * Authenticate a User.
 */
public static Person authenticate(String email, String password) {
Logger.info("email: " + email + " and password is:" + password);
    return find.where().eq("email", email).eq("password", password).findUnique();
}

/**
 * Retrieve all users.
 */
public static List<Person> findAll() {
return find.all(); …
Run Code Online (Sandbox Code Playgroud)

playframework-2.0

5
推荐指数
1
解决办法
4180
查看次数

为什么isset()总是在自定义Object上返回FALSE

我无法理解这种行为:我的isset()检查总是在具有值的值上返回falseproperty!

<?php

  class User {
    protected $userId; // always filled
    protected $userName; // always filled

    /**
     * Magic method for the getters.
     * 
     * @param type $property
     * @return \self|property
     */
    public function __get($property) {
        if (property_exists($this, $property)) {
            return $this->$property;
        } else {
            throw new Exception('property '.$property.' does not exist in '.__CLASS__.' class');
        }
    }

  }

?>
Run Code Online (Sandbox Code Playgroud)

当我从另一个类检查此变量时,使用以下内容:

isset($loggedUser->userName); // loggedUser is my instantiation of the User.php
Run Code Online (Sandbox Code Playgroud)

它返回FALSE?? 但是当我__isset()在User.php中重载函数时,我TRUE …

php

3
推荐指数
2
解决办法
3483
查看次数

我应该在什么情况下使用Ebean或EbeanServer?

我知道我可以使用EbeanEbeanServer访问数据库.EbeanServer有比Ebean更多的API方法,Ebean上的许多方法Ebean.find(Class)等实际上只是在'default/primary'EbeanServer上调用方法的一种方便方法.

我的问题:

  • 我可以通过调用Ebean.getServer(String name)使用EbeanServer提供的所有apis来获取EbeanServer对象吗?
  • 在什么情况下我应该使用Ebean而不是EbeanServer(反之亦然)?
  • EbeanServer是否适合以编程方式创建EbeanServer?
  • Ebean适合通过配置文件创建EbeanServer吗?

在Play 2.4中,不需要ebean.properties,ebean配置可以放在application.conf中,我想我应该在Play framwork 2.4中使用Ebean,对吧?

谢谢你的建议.

EbeanServer api doc

Ebean api doc

playframework ebean

3
推荐指数
1
解决办法
791
查看次数

为什么jQuery .submit不起作用?

在提交表单之前,我试了几乎一个小时来弄清楚如何进行一些验证.我的表格是这样的:

<!doctype html>
<head>
<title>sample</title>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">      </script>
<script>
 $("#myform").submit(function() {
   alert("it is not working");
   return false;
 });
</script>
</head>
<body>
  <form id="myform">
   <input id="foo" value="Change me and press enter"/>
   <input type="submit" />
  </form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

它不适用于IE,Chrome FF :-(我必须做一些非常错误的事情,但是什么?

编辑

工作样本:

<!doctype html>
<head>
<title>sample</title>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"> </script>
<script>
    $(document).ready(function() {
    $("#myform").submit(function() {
        alert("Now it is def working!");
        return false;
    });
});
</script>
</head>
<body>
<div id="myform">
<form id="myform">
    <input id="foo" value="Change me and press enter"/>
    <input type="submit" />
</form> …
Run Code Online (Sandbox Code Playgroud)

jquery form-submit

2
推荐指数
1
解决办法
2万
查看次数

从Scala模板访问翻译的i18n消息(Play!Internationalization)

在我的游戏!2.0应用程序我想定义以下语言:

# The application languages
# ~~~~~
application.langs=en-GB,de-DE,nl-NL
Run Code Online (Sandbox Code Playgroud)

我还创建了3个以相应语言代码结尾的文件:

Messages.en-GB
Messages.de-DE
Messages.nl-NL
Run Code Online (Sandbox Code Playgroud)

当我启动应用程序而没有任何翻译密钥请求时,我收到以下错误消息:

conf/application.conf: 12: Key 'de-DE' may not be followed by token: ',' (if you intended ',' to be part of the value for 'de-DE', try enclosing the value in double quotes)
Run Code Online (Sandbox Code Playgroud)

此外,当尝试从Scala模板访问消息时,我仍然看到相同的消息.我通过以下代码请求消息:

@Messages("login.page")
Run Code Online (Sandbox Code Playgroud)

我根据Play手册进行了上述更改:http://www.playframework.org/documentation/2.0/JavaI18N.所以我有两个问题:

  1. 如何设置默认语言并在1.2.4中更改它(Lang.change("en-GB"))
  2. 如何从Scala模板访问消息?

internationalization playframework-2.0

2
推荐指数
1
解决办法
7504
查看次数

如何在PLay中开始Play Framework 2.0中的手动测试!V1?

我为Play编写了一个简单的测试类!2.0:

public class TestLogin {

    @Test
    public void test() {
    running(testServer(3333, fakeApplication(inMemoryDatabase())), HTMLUNIT, new Callback<TestBrowser>() {
        @Override
        public void invoke(TestBrowser browser) {
        browser.goTo("http://localhost:3333");
        assertThat(browser.$("section h1").first().getText()).isEqualTo("Login");

        }
    });
    }
}
Run Code Online (Sandbox Code Playgroud)

在Play v1中,您可以执行以下命令:

play test
Run Code Online (Sandbox Code Playgroud)

你可以转到http://localhost:9000/@tests.但是现在在Play 2.0中这不起作用而且没有记录?我只是想开始我的Selenium测试,手动(每个测试用例/方法)自动化(一堆测试用例).

如何在Play2.0中实现这一目标?

BTW:运行命令播放测试在终端输出以下内容:

[warn] 1 warning
[info] No tests to run for test:test 
Run Code Online (Sandbox Code Playgroud)

playframework-2.0

2
推荐指数
1
解决办法
2579
查看次数

Global类中的访问会话

我非常需要我的用户对象,所以我想我会将它存储在Cache中.因为我不知道什么时候它从Cache中被销毁,所以我把它作为一个interceptor.所以我定义了以下代码:

@Override
public Action<?> onRequest(Request request, Method actionMethod) {
    // find the user based on the userId that is stored in the session
    // scope.
    String userId = session.get("user"); // does not work
    User loggedInUser = (User) Cache.get(userId);
    if (loggedInUser == null) {
        loggedInUser = User.getUerById(userSyscode);
    }
    return super.onRequest(request, actionMethod);
}
Run Code Online (Sandbox Code Playgroud)

我以为我可以用:

session.get("user");
Run Code Online (Sandbox Code Playgroud)

但在我看来,就像session是无法访问Global class,我做错了什么?

playframework-2.0

1
推荐指数
1
解决办法
3170
查看次数