Is it possible to define things externally into Properties files for our annotations on Spring Controllers?
Suppose I have the following Controller
@Controller
@RequestMapping(value = "processModel.jsp")
public class ProcessorController {
@RequestMapping(method = RequestMethod.GET)
public String displayModel() {
//Code to load processor
return "processModel";
}
@RequestMapping(method = RequestMethod.POST, params="submit=Refresh")
public String refreshModel() {
//Code to refresh data
return "processModel";
}
@RequestMapping(method = RequestMethod.POST, params="submit=Save Model")
public String saveModel() {
//Code to save model
return "processModel";
}
}
Assume the following HTML is generated:
<input type="submit" name="submit" value="Save Model" />
<input type="submit" name="submit" value="Refresh" />
It’d be nice to have these params externalized so that we only have to define them once in a properties file. That way if we need to change the label on a submit button in the JSP, we only need to change it in the properties file, rather than in two places.
Is this possible?
Annotation parameter values need to be a literal or refer to a constant field, so the externalized dynamic value cannot be injected into the @RequestMapping annotation. An alternative may be to drive the behavior using some other hidden form variable mapped to a literal(SAVEMODEL/REFRESH) instead of the text that is displayed to the user(you may get a requirement to internationalize the text displayed to the user at some point and this model will break then)