The initDefaultModelVariables closure puts some of the static data into the model:
// Move this to core and look for a service/bean that exposes the menu?
static initDefaultModelVariables = { model ->
model['menuStructure'] = menuStructure
model['menuByUrl'] = menuByUrl
model['menuByName'] = menuByName
}
Description
I have a service storing navigation data. This data is static even though it's a service (due to other workarounds).
If I change the data (in NavigationService), usually grails will fail to reload the non-transactional service and return:
HTTP ERROR: 500
java.lang.NullPointerException: Cannot get property: fullName on null object
The controller:
The initDefaultModelVariables closure puts some of the static data into the model:
// Move this to core and look for a service/bean that exposes the menu?
static initDefaultModelVariables = { model ->
model['menuStructure'] = menuStructure
model['menuByUrl'] = menuByUrl
model['menuByName'] = menuByName
}
This fails, even if services inject, because of a deliberate typo:
import org.springframework.mail.MailException
import org.springframework.mail.MailSender
import org.springframework.mail.SimpleMailMessage
class MailService {
staticboolean transactional = false
MailSender mailSender
SimpleMailMessage mailMessage // a "prototype" email instance
/**
* Send a list of emails
*
* @param mail an object with to, text and subject (from is in resources.xml)
*/
def sendEmail(mail) {
// Create a thread safe "sandbox" of the message
SimpleMailMessage message = new SimpleMailMessage(defaultMailMessage)
message.to = mail.to
message.text = mail.text
message.subject = mail.subject
try {
mailSender.send(message)
} catch (MailException ex) {
println "Failed to send email"
ex.printStackTrace()
}
}
}
If you correct the typo (change decl of mailMessage to defaultMailMessage) and reload, you get the 500 error
Marc Palmer - 09/Jan/07 04:03 PM This fails, even if services inject, because of a deliberate typo:
import org.springframework.mail.MailException
import org.springframework.mail.MailSender
import org.springframework.mail.SimpleMailMessage
class MailService {
staticboolean transactional = false
MailSender mailSender
SimpleMailMessage mailMessage // a "prototype" email instance
/**
* Send a list of emails
*
* @param mail an object with to, text and subject (from is in resources.xml)
*/
def sendEmail(mail) {
// Create a thread safe "sandbox" of the message
SimpleMailMessage message = new SimpleMailMessage(defaultMailMessage)
message.to = mail.to
message.text = mail.text
message.subject = mail.subject
try {
mailSender.send(message)
} catch (MailException ex) {
println "Failed to send email"
ex.printStackTrace()
}
}
}
If you correct the typo (change decl of mailMessage to defaultMailMessage) and reload, you get the 500 error
If you correct the typo (change decl of mailMessage to defaultMailMessage) and reload, you get the 500 error