正如标题所说,我正在尝试从html选择表单中检索所选项目.我尝试使用以下代码执行此操作,但它不起作用!城市值始终为NULL但地址字段返回正确的值...
form.html:
#{extends '/Admin/admin.html' /}
#{form @save(id)}
#{ifErrors}
<p class="error">
Please correct these errors.
</p>
#{/ifErrors}
<p>
<label>Adresse</label>
<input type="text" name="adress" value="${flash.adress}" id="adress" />
<span class="error">#{error 'adress' /}
</p>
<p>
<label>Ville</label>
<select size="1" >
#{list items:cities, as:'city'}
<option name="city" id="city" value="${flash.city}">${city}</option>
#{/list}
</select>
<span class="error">#{error 'city' /}
</p>
<p>
<input type="submit" value="Publier l'annonce" />
</p>
#{/form}
Run Code Online (Sandbox Code Playgroud)
保存方法:
public static void save(long id, String adress, @Required Place city){
System.out.println(city);
Admin.index();
}
Run Code Online (Sandbox Code Playgroud) 在login,可以使用url设置的值将用户重定向到请求登录的页面flash.
是否可以使用相同的用例,将用户重定向到注销后请求注销操作的页面?
我使用JPA-> Hibernate.PlayFramework.我想要有关系.
Category - 1:n -> Tag
Run Code Online (Sandbox Code Playgroud)
每个类别都可以有许多标签,但标签不知道它.
所以,我喜欢这样:
Run Code Online (Sandbox Code Playgroud)@Entity public class Category ... { @OneToMany public List<Tag> tags = new LinkedList<Tag>(); }
我测试过:
@Test public void playWithTags(){
Tag tag1 = new Tag("tag1").save(); // managed by playframework
Category cat1 = new Category("cat1");
cat1.tags.add(tag1);
cat1.save();
// check if tag1 and cat1 were saved
assertEquals(1, Tag.count());
assertEquals(1, Category.count());
Category cat2 = new Category("cat2");
cat2.tags.add(tag1);
cat2.save();
}
Run Code Online (Sandbox Code Playgroud)
结果是:
16:18:01,555 ERROR ~ Duplicate entry '1' for key 'tags_id'
16:18:01,555 ERROR ~ Could not synchronize …Run Code Online (Sandbox Code Playgroud) 有没有办法让玩!框架忽略斜杠和?部分URL?
通常,如果我有以下内容:
www.123.com/api/link/http:www.bla.com/?contenId=123&User=test
它不会起作用.在这种情况下,我想要做的只是在String变量中的URL的最后部分中链接以保存它.我想我可以强制客户更换/和?别的东西,但我宁愿保持简单.
我的第一个想法是,可能有一种方法来配置路由,以便我们有类似的东西:
/api/link/{data}
哪里data会保留URL的剩余部分.但是无法知道如何做到这一点.
我正在关注code.google的教程,但我的示例未能提供以下跟踪:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.google.code.morphia.mapping.MappedClass.callLifecycleMethods(MappedClass.java:323)
at com.google.code.morphia.mapping.Mapper.toDBObject(Mapper.java:371)
at com.google.code.morphia.DatastoreImpl.entityToDBObj(DatastoreImpl.java:674)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:722)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:802)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:796)
at models.com.vlist.activity.classes.TestMongoData.testUserData(TestMongoData.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.code.morphia.mapping.MappedClass.callLifecycleMethods(MappedClass.java:304)
... 28 …Run Code Online (Sandbox Code Playgroud) 手动Web路由的目的是什么?为什么不是每个人都只是自动映射URL和模块/方法/函数名称?
我认为你可以从全自动映射开始,然后你就可以使用Apache mod_rewrite或mod_redirect,或者如果你想以一种改变URL的方式重构,而不破坏现有的URL.
我正在尝试在我的程序中创建一个功能,允许用户将他们的数据下载到文件中.
现在,我在我的一个控制器中有一个方法,它创建一个具有特定名称的File对象,并使用FileWriter将内容加载到文件中.完成后,File对象将传递到renderBinary().这会按预期将文件发送给用户.
但是,这会将文件保存在我的Play中!项目目录发送之前.这让我想知道当有许多用户试图生成和下载文件时会发生什么.他们会互相覆盖吗?
简而言之,生成文件并通过renderBinary发送文件的最佳方法是什么?
我是使用java玩框架的新手.我决定从简单的待办事项列表开始.我在网上找到了一些文档但只支持play 2.0并且他们正在导入视图并使用预定义的ToDo方法,问题是我只在1.2.4版上工作所以任何关于可以使用什么而不是导入视图和使用ToDo的帮助重新定义的方法?
当我转到sbt并输入命令"start"时,它会向我显示它应该显示给我的内容,一个带有简单消息的简单页面.
但是当我去sbt并输入命令"run"时,它会显示一个欢迎屏幕.路由文件显示发送到应用程序控制器的默认页面和索引功能.索引函数调用index.scala.html.
为什么选择"运行"时我会继续获得欢迎屏幕?我无法摆脱欢迎页面.