问题:有没有办法用request.JSON数据进行自动命令对象绑定?
在我的grails控制器中给出这个简单的Command对象:
class ProfileCommand{
int id
String companyName
static constraints = {
companyName blank: false
id nullable: false
}
@Override
public String toString() {
return "ProfileCommand{id=$id, companyName='$companyName'}";
}
}
Run Code Online (Sandbox Code Playgroud)
和我的控制器方法签名:
def update(ProfileCommand command) {...}
如何将request.JSON数据存入我的命令对象?
到目前为止,我能够做到的唯一方法是在update()方法中手动创建命令对象,传递request.JSON作为构造函数参数:
def command = new ProfileCommand(request.JSON)
log.debug "Command object contents: $command"
Run Code Online (Sandbox Code Playgroud)
上面的debug命令产生:
Command object contents: ProfileCommand{id=1, companyName='Blub Muckers'}
Run Code Online (Sandbox Code Playgroud)
这正是我想要的(对于上述解决方案,Oliver Tynes大声喊出来).不幸的是,command.validate()在创建命令后调用会产生以下异常:
Class org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException
Message Tag [validate] is missing required attribute [form]
Run Code Online (Sandbox Code Playgroud)
我正在使用v2.0.3,uris产生了与v2.0.4相同的异常.
更新
Grails邮件列表中的每个Ian Roberts,您需要将@Validateable注释添加到命令类才能开始validate()工作.谢谢,伊恩!
我有一个grails应用程序,其中包含一系列嵌套目录中的各种javascript文件.我想通过资源插件管理它们,但不想显式注册每个插件.
Web目录结构
webapp
app
controller
controller1.js
controller2.js
...
model
model1.js
...
view
view1.js
Run Code Online (Sandbox Code Playgroud)
什么是伟大的只是在我的AppResources.groovy文件中声明:
resource url: 'app/**/*.js'
但这不起作用 - 抛出一个空指针.我试过了:
resource url: 'app/**' 但没有运气
我以为我会在配置文件中放入一些代码,这些代码将通过目录结构进行处理,但这似乎不起作用.这是我尝试过的:
def iterClos = {
it.eachDir( iterClos );
it.eachFile {
resource url: ${it.canonicalPath};
}
}
iterClos( new File("$grails.app.context/app") )
Run Code Online (Sandbox Code Playgroud)
不幸的是,这也失败了.
有没有人有任何想法我怎么能做到这一点?
我正在测试一个指令.该指令监视范围变量,但从不调用手表.将$watch呼叫直接置于单元测试内部.为什么$watch指令中没有被调用?
谢谢!
这是我原来的测试.该指令有一个手表,看着'reEvalCreateDate'.它从未被调用,日期字符串始终为空.
it('should inject a date string', function()
{
scope.reEvalCreateDate = reEvalCreateDateAsNumber;
expect(elm.text()).toBe('');
scope.$digest();
expect(elm.text()).toBe(new Date(reEvalCreateDateAsNumber).toUTCString());
});
Run Code Online (Sandbox Code Playgroud)
作为测试,我把手表放在单元测试中.它被正确调用并且测试通过.
it('should inject a date string', function()
{
scope.$watch('reEvalCreateDate', function(newValue, oldValue)
{
var date = new Date(newValue);
scope.dateString = date.toUTCString();
dump(scope.dateString)
});
scope.reEvalCreateDate = reEvalCreateDateAsNumber;
expect(elm.text()).toBe('');
scope.$digest();
expect(elm.text()).toBe(new Date(reEvalCreateDateAsNumber).toUTCString()); //This passes!
});
Run Code Online (Sandbox Code Playgroud)
这是带有watch语句的指令代码.
link: function(scope, element, attrs)
{
scope.$watch('show',function(shouldShow){
console.log('should show reeval timer? ' + shouldShow);
if(shouldShow) {
$(element).fadeIn('slow');
}
else …Run Code Online (Sandbox Code Playgroud) Jenkins没有收到junit格式的报告,导致报告没有列在项目的状态屏幕中.
junit格式的报告数据由名为Karma-runner(以前称为Testacular)的测试框架生成.被忽略的文件创建于/target/surefire-reports- 创建surefire生成的报告的位置.报告数据看起来几乎与maven surefire插件生成的报告数据相同,只是它的父元素<testsuites>代替<testsuite>- <testsuite>是surefire生成的报告作为报告文件的父元素.这是来自业力生成的junit格式报告的片段,命名为TEST-karma.resultsTest.xml:
Junit格式的Karma生成的报告文件, TEST-karma.resultsTest.xml
<?xml version="1.0"?>
<testsuites>
<testsuite name="PhantomJS 1.9 (Mac)" package="karma.tests" timestamp="2013-04-10T13:32:26" id="0" hostname="jgmbp.local" tests="16" errors="0" failures="0" time="0.069">
<properties>
<property name="browser.fullName" value="Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.0 Safari/534.34"/>
</properties>
<testcase name="successfully cancels a new member" time="0.006" classname="karma.tests PhantomJS 1.9 (Mac).Household Controller"/>
<testcase name="should parse an existing re-eval create date, setting the data in scope" time="0.003" classname="karma.tests PhantomJS 1.9 (Mac).Re-Eval Controller"/> …Run Code Online (Sandbox Code Playgroud) 伙计们,
我有一个由JSONStore支持的组合框组件.加载到商店的数据为组合框的值返回null.该值为int.JSON解码过程将空值转换为零; 导致组合框在尝试查找pk时无法呈现,在其后备存储中不存在零.
我找到了data.Field对象的useNull:config选项,升级到3.3.0 Final并将组合框的int值设置为useNull:true.遗憾的是,这根本没有任何影响.解码后的值仍然从零变为零.
当JSON字段的数据为空时,有关如何不将字段设置为零的任何想法?
这是一张正在发生的事情的照片.注意数据:value为零,但JSON值为null.
谢谢!
(gah!stoopid声誉<10所以我不能直接发布图片.查看此处: debug pic)
此外,这是我的商店的字段配置:
fields: [
{name:"id", type:"int"},
{name:"occurenceDate", dateFormat: 'Y-m-d\\TH:i:s', type:"date"},
{name:"docketNumber", type:"string"},
{name:"courtLocationId", type:"int", useNull:true},
{name:"assignedOfficerId", type:"int", useNull:true},
{name:"primaryIncidentTypeId", type:"int", useNull:true},
{name:"secondaryIncidentTypeId", type:"int", useNull:true},
{name:"tertiaryIncidentTypeId", type:"int", useNull:true},
{name:"incidentLocation", type:"string"},
{name:"summary", type:"string"},
{name:"personalItemsSeized", type:"string"},
"supplements",
"parties",
"judgeIds"
]
Run Code Online (Sandbox Code Playgroud) 问题
我需要直观地格式化输入字段,以帮助用户知道他们应该键入什么作为电话号码.例如,我想接受一个电话号码为3位区号,3位前缀和4位后缀:(207)555-1212.我想要:
最好的方法是什么?
注意:这不是用于显示数字 - 我可以使用过滤器.这用于格式化input字段中的数据.
谢谢你的帮助!
所有,
有谁知道如何指导SqlQuery类为非托管实体查询返回的列使用别名?
我正在尝试使用SqlQuery Hibernate类来创建非实体POJO的List,但是在尝试对SQL查询中的列进行别名时遇到了麻烦.当我尝试将别名放入我的sql(例如SELECT o.id as orderId, ps.code as prescriptionStatus...)时,hibernate抱怨它找不到列"x",其中列"x"是非别名列名(例如"id"而不是"orderId").
如果我没有别名我的返回列,一切都很好,但我的POJO然后被迫拥有带有非别名字段名称的属性,或者我必须管理POJO中的映射(具有漂亮名称的getter返回非别名字段名称).
这是我的代码
//TODO: change builder to a name query --jg
StringBuilder sql = new StringBuilder();
sql.append("SELECT o.id,\n");
sql.append(" pet.name,\n");
sql.append(" o.order_date,\n");
sql.append(" rx_view.prescription_id,\n");
sql.append(" rx_view.code\n");
sql.append("FROM order_line_item oli\n");
sql.append(" JOIN order_detail o\n");
sql.append(" ON o.id = oli.order_id\n");
sql.append(" JOIN order_line_item_pet olip\n");
sql.append(" ON olip.order_line_item_id = oli.id\n");
sql.append(" JOIN pet\n");
sql.append(" ON pet.id = olip.pet_id\n");
sql.append(" LEFT JOIN (SELECT olip.order_line_item_id order_line_item_id,\n");
sql.append(" olip.prescription_id,\n");
sql.append(" ps.code\n");
sql.append(" FROM …Run Code Online (Sandbox Code Playgroud) 调用repeater('#myTable tr','Rows').count();返回a Future,而不是整数.我需要获取整数值,以便我可以确认在表中添加了一行.
it('should add a new user when save button is clicked',function()
{
showModal();
//here I'm trynig to store the row count of my table into a local variable.
//a future is returned who's 'value' field is undefined.
var memberCount = repeater('#memberTable tr','Member Rows').count();
//this outputs 'undefined'
console.log(memberCount.value);
input('editedMember.name').enter('John');
input('editedMember.grade').enter(5);
input('editedMember.ladderPosition').enter(3);
element('#saveMemberButton').click();
sleep(1);
expect(element(modalId).css('display')).toBe('none');
//here is where I want to do the comparison against the above stored memberCount
expect(repeater('#memberTable tr', 'Member Rows').count()).toBe(memberCount.value + 1); …Run Code Online (Sandbox Code Playgroud) 我想在 Web 应用程序的 DAO 单元测试中使用 hsql。该 Web 应用程序是针对 mysql 编写的,并在同一 mysql 数据库中使用三种不同的模式。某些模式与其他模式中的数据具有 FK 关系。如果我要进行单元测试,我必须能够针对可以保存多个模式的数据库执行。
我知道 HSQL 支持多个模式,但我不知道如何配置 hsql 为内存数据库设置多个模式。我读到我可以在 server.properties 文件中定义多个模式,但该文件需要位于调用 java 类的位置 - junit.jar 位置?如果是这样,我的 Java Maven 应用程序将很难支持。我怎么能够:
我希望我能够理清彼此的模式,但目前这是不可能的。
感谢您的帮助!
我的环境:Grails v2.1.1
我需要在战争过程中运行一个小型实用程序应用程序.这个应用程序生成我想要包含在我的war文件中的文件.我已经尝试将代码放在BuildConfig.groovy的grails.war.resources中,但我没有看到错误,或者我希望创建的文件.
有谁知道如何执行这个实用程序的应用程序,以便它的输出在我的战争?
这是在终端实例中运行的命令:
sencha app build -e production -d $stagingDir/production
Run Code Online (Sandbox Code Playgroud)
这是我尝试通过运行它grails.war.resources在BuildConfig.groovy:
grails.war.resources = { stagingDir ->
//calling echo() does nothing. I don't see the comment in the build output
echo(message:'executing grails.war.resources')
def outputDir = new File("${stagingDir.getParentFile().getPath()}/target/ranForReal")
def command = """sencha app build -e testing -d ${outputDir.getPath()}"""
def executionDir = new File("${stagingDir.getParentFile().getPath()}/web-app")
def proc = command.execute(null,executionDir)
proc.waitFor()
//my desperate attempt to see if anything is happening. I'd expect an error here
def x = 1/0 …Run Code Online (Sandbox Code Playgroud) angularjs ×3
grails ×3
karma-runner ×2
combobox ×1
end-to-end ×1
extjs ×1
formatting ×1
hibernate ×1
hsqldb ×1
input ×1
jenkins ×1
jsonstore ×1
junit ×1
maven ×1
resources ×1
unit-testing ×1