여러 계정 ID에 대한 엔티티 ID가 있는지 확인하는 쿼리를 실행 중입니다. 결과 집합이 null이 아니면 오류를 던지거나 플래시 메시지를 표시해야합니다.Grails - 맞춤 Flash.message 렌더링
방법에 대한 코드는 다음과 같습니다 :
내가 플래시 메시지를 다음과 같은 방식으로 오류 렌더링 내 관점에서def save() {
def SAMLInfoInstance = new SAMLInfo(params)
def account = Account.get(params?.accountId)
SAMLInfoInstance.setAccount(account)
def samlInfoInstanceList = SAMLInfo.executeQuery("from SAMLInfo " +
" where account.id <> ? " +
" and entityId = ?", [SAMLInfoInstance.accountId, SAMLInfoInstance.entityId])
if (samlInfoInstanceList?.size > 0){
flash.message = message(code: 'test.not.created.message', args: [message(code: 'SAMLInfo.label', default: 'SAMLInfo'), SAMLInfoInstance.entityId])
/*flash.message = "default.not.created.message"
flash.args = ["SAMLInfo", SAMLInfoInstance.entityId]
flash.default = "SAMLInfo cannot be created"
*/
render(view: "create", model: [SAMLInfoInstance: SAMLInfoInstance])
return
}
if (!SAMLInfoInstance.save(flush: true)) {
render(view: "create", model: [SAMLInfoInstance: SAMLInfoInstance])
return
}
flash.message = message(code: 'default.created.message', args: [message(code: 'SAMLInfo.label', default: 'SAMLInfo'), SAMLInfoInstance.entityId])
redirect(action: "list", id: SAMLInfoInstance.account.id)
}
: 내 message.properties 파일에서
<g:if test="${flash.message}">
<br/>
<div class="message" role="status">
<g:message code="${flash.message}" args="${flash.args}" default="${flash.default}"/>
</div>
<br/>
</g:if>
<br/>
<g:renderErrors bean="${SAMLInfoInstance}" as="list" />
을, 다음 줄이 있습니다 :
test.not.created.message=The SP url {1} is not allowed for this account. Please enter a different value.
이 코드를 실행하면 플래시 메시지가 문자열로 표시됩니다. "test.not.created.message"와 같은 메시지를 생성합니다. 또한 flash.message를 표시하는 다른 페이지로 이동할 때마다이 문자열이 전달되어 전달됩니다. 나는 grails와 groovy에 익숙하지 않으며 이에 대한 도움을 주시면 감사하겠습니다.
감사합니다.
그게 :) 다음 코드를 사용하여 내 문제를 해결했다 : 'Obj.errors.rejectValue ('entityId', 'Obj.entityId.clash.not.created.message', [message (code : 'Obj.label', 기본값 : 'Obj url'), Obj.entityId] as Object [], '이 Obj URL은이 계정에 허용되지 않습니다. 다른 값을 입력하십시오.')' http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/validation/Errors.html#rejectValue에서 찾을 수있는 메소드 서명을 사용합니다. –
무엇을 너 무슨 뜻이야? 플래시 변경 요청? –
또한 답변이 도움이 되었으면 언제든지 수락하십시오. ;) –