2012-04-04 5 views
2

こんにちは、検証エラーのarraylistを解析し、それをdiaply。私は、ArrayListのどのようにエラーの配列リストを解析し、検証エラーとして表示するのですか

[passwordinsufficientuniquechar, passwordmaxrepeat, passwordinsufficientuniqueno, passwordnotenoughnumbers] 

を持っていると私は私がのWebflowを使用しています

passwordcontainsusername=Your new password cannot contain your user name. 
passwordtooshort=Your new password must be at least 8 characters long. 
passwordtoolong=Your new password cannot exceed 50 characters. 
password.change.different=The new password and the confirmed password values do not match. 
passwordmaxrepeat=Your new password cannot contain more than 4 instances of the same character. 
passwordequalsoldpassword=Your new password cannot be a previously used password. 
passwordnotenoughnumbers=Your new password must contain at least 1 number or punctuation character. 
passwordnotallowedchar=Your new password contain one or more characters that are not allowed. 
password.change.validateerror=The account password and the current password do not match. 
passwordnotenoughchars=Your new password must contain at least 2 letters. 
passwordlessthan24hours=You cannot change your password more than three times in 24 hours. 
passwordinsufficientuniquechar = Your new password must contain at least 5 unique characters. 
passwordinsufficientuniqueno =Your new password must contain at least 2 unique numbers (symbols count as numbers). 

ようmessage.propertiesで対応するメッセージを持っています。では、これらのメッセージをo/pに解析して、プロパティファイルからメッセージを表示する方法を教えてください。

答えて

1

grailsのコンベンションは、メッセージをgrails-app/i18n/messages.propertiesに入れることです。メッセージ・コードの配列を持っている場合、あなたはこのようにそれを行うことができます

<g:message code="passwordtooshort"/> 

:その後、あなたの意見では、あなたはg:messageタグを使用することができます

<g:each in="${messageCodes}"> 
    <g:message code="${it}"/> 
</g:each> 

ビューは一般的に行うには最高の場所ですこれが、あなたは、コントローラの内部で変換を行う必要がある場合、あなたはそのようにそれを行うことができます。

def translation = message(code: 'passwordtooshort') // single code 
def translations = messageCodes.collect { message(code: it) } // list of codes 
+0

DEFの翻訳をプロパティからのすべてのメッセージがobject.Howにファイルを置くのを助けた私は、翻訳オブジェクトをバインドしますコマンドオブジェクトにエラーメッセージとして表示しますか? –

+0

通常、コマンドオブジェクトに制約を加え、validateが呼び出されたときにコマンドオブジェクトにエラーを作成します。コマンドクラス名は、フィールド名と制約名と組み合わされて、messages.propertiesで検索されるキーを作成します。 – ataylor

+0

これはうまくいきました....私は、コマンドオブジェクトを追加するのを忘れていました。それがエラーを作り出していました。返信いただきありがとうございます。 –