I have tried a code about auto generating id. I want to try it on JTextField, but I don't know where i should put it.
Here is my code:
--PembelianController.groovy--
String generateID() {
String date = DateTime.now().toString("yyyyMMdd")
List list = findAllPembelian([orderBy: 'noNota', orderDirection: 'desc'])
Integer num = list.size()==0? 0: list[0].kode[12..-1].toInteger() + 1
return String.format("NT00%s%04d", date, num)
}
--PembelianView.groovy--
label('No Nota:')
textField(id: 'noNota', columns: 20, text: bind('noNota', target: model, mutual: true), errorPath: 'noNota')
errorLabel(path: 'noNota', constraints: 'wrap')
Well, it depends on when you want to do it. You can assign textField.text = generateID()
at any time. You may assign the value during the binding
textField(id: 'noNota', columns: 20, errorPath: 'noNota',
text: bind('noNota', target: model, mutual: true, value: generateID()))