【发布时间】:2013-04-11 04:13:23
【问题描述】:
Griffon in Action 书中的第 3.6.1 段有一个关于 mortageCalc 应用程序的练习。
环境:
- Win 7 Pro,64 位
- IntelliJ IDEA 12.1 版
- Griffon-1.2.0 JDK 1.6
我有 MortgageCalView:
package mortgagecal
application(title:'Mortgage Calculator', pack:true, locationByPlatform:true)
{
panel(border: emptyBorder(6)) {
gridLayout(rows:4, columns:2, hgap:6, vgap:6)
label('Principal:')
textField(text: bind(target:model, 'principal',
value:'$200,000',
validator: model.validatePrincipal,
converter: model.convertPrincipal))
label('Interest Rate:')
textField(text: bind(target:model, 'monthlyRate',
value:'6.5%',
validator: model.validateRate,
converter: model.convertRate))
label('Term:')
textField(text: bind(target:model, 'months',
value:'30',
validator: model.validateTerm,
converter: model.convertTerm))
label('Monthly Payment (P&I):')
textField(editable:false,
text: bind(source: model, sourceProperty: 'payment',
sourceEvent: 'propertyChange',
converter: model.convertPayment))
}
}
和MortgageCalModel:
package mortgagecal
import groovy.beans.Bindable
import java.text.NumberFormat
import java.text.DecimalFormat
@Bindable
class MortgageCalModel {
float principal
float monthlyRate
float months
float getPayment() {
return principal * monthlyRate /
(1-Math.pow(1/(1+monthlyRate),months))
}
private currencyFormat = NumberFormat.currencyInstance
private percentFormat = new DecimalFormat('0.00%')
def validatePrincipal = {
try {
float principal = currencyFormat.parse(it)
return principal > 0
} catch (Exception e) {
return false
}
}
def convertPrincipal = currencyFormat.&parse
def validateRate = {
try {
float rate = percentFormat.parse(it)
return rate > 0 && rate < 0.30
} catch (Exception e) {
return false
}
}
def convertRate = {
return percentFormat.parse(it) / 12
}
def validateTerm = {
try {
def term = Float.parseFloat(it)
return term > 0 && term < 100
} catch (Exception e) {
return false
}
}
def convertTerm = {
return Float.parseFloat(it) * 12
}
def convertPayment = {
return currencyFormat.format(it)
}
}
运行时出现错误:
捕获:groovy.lang.MissingMethodException:没有方法签名: mortgagecal.MortgageCalView.application() 适用于参数 类型:(java.util.LinkedHashMap, mortgagecal.MortgageCalView$_run_closure1) 值:[[title:Mortgage 计算器,pack:true,locationByPlatform:true],...] groovy.lang.MissingMethodException:没有方法签名: mortgagecal.MortgageCalView.application() 适用于参数 类型:(java.util.LinkedHashMap, mortgagecal.MortgageCalView$_run_closure1) 值:[[title:Mortgage 计算器,包:真,locationByPlatform:真],...]在 mortgagecal.MortgageCalView.run(MortgageCalView.groovy:3)
但是,当我在命令提示符下运行时,它工作正常:
cd D:\work\griffon\mortgageCal>
griffon run-app
所以,我的 IntelliJ 出了点问题……
【问题讨论】:
-
如果我这样做:
griffon create-app mortgageCalc,然后cd mortgageCalc然后将这两个文件粘贴到模型和视图类中,它对我来说很好...... -
@tim_yates 谢谢。我刚刚确认从命令提示符运行时它可以正常工作,所以我刚刚编辑了我的问题。
-
在使用 IntelliJ 和 Griffon 时,请务必调用以下命令(从命令行): griffon integration-with --idea 此命令生成包含完整依赖信息的 IDEA 项目文件。
-
@aalmiray 在本书第 51 页上,上面写着使用“--intellij”
-
您可以使用--idea 或--intellij,两者都受支持:-)
标签: groovy intellij-idea griffon