开发者

How to assign two different values to two different variables by selecting only one radio button in Grails?

I have this on the frontend:

<input type="radio" name="adminArg1" value="brief" checked="true">
    Brief information
</input开发者_如何转开发>

I have this on the backend:

String adminArg1 = params.adminArg1
String adminArg2 = params.adminArg2

I want to assign 'brief' to adminArg1, but also 'null' to adminArg2, whenever I click on the radio. Is that possible?


You could either use Groovy's multiple assignment to assign the values:

def (adminArg1, adminArg2) = (params.adminArg1 == 'brief' ? ['brief',null] : ... )

or if you're using some kind of validating class (e.g., Command Object or Domain Class) you can override the Groovy setters:

public void setAdminArg1(String adminArg1) {
    if (adminArg1 == 'brief') {
        this.adminArg1 = adminArg1
        this.adminArg2 = null
    } else {
     ...
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜