I'm getting started with Spring Roo. So far so good, it seems like a decent Java option for CRUD based applications.
I've created a basic web app using one of the SpringRoo tutorials online as a base.
I've set up the basic scaffolding, and it appears that objects that have a one-to-many relationship are listed as such in the application:
List all Exam Modules
Difficulty Category Exam Id
Easy Software Design 2013-02-28 15:01:29.0 2013-02-28 15:01:29.0 Test Software Exam
Exam Id is a reference to an Exam entity as follows:
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;
@RooJavaBean
@RooJpaActiveRecord(versionField = "", table = "exam")
@RooDbManaged(automaticallyDelete = true)
public class Exam {
@Override
public String toString() {
return id + ": " + desc;
}
}
Before, toString was configured using @RooToString
This has not been reflected in the web app, so perhaps the string that is displayed there does not invoke the toString method.
My code in the jspx is as follows:
<table:column id="c_com_mypackage_examino_domain_ExamModule_examId" property="examId" z="iz7M0ohWIJEbf7nEYqPLkvKKtcE="/>
Any idea on how to get this exam entity to print out a nice, family friendly string?
Look in the ApplicationConversionServiceFactoryBean.java (or .aj). There will be a method along the lines of
public Converter<Exam, String> getExamToStringConverter()
or
public Converter<ExamPK, String> getExamToStringConverter()
Change that so it only includes the fields you want to see.
Alternatively, you can just add a bean style method in Exam.java that returns the string you want and call it as a property. This assumes you've created a method named getMyExamId() that returns the string you want. Notice you'll need to change z to 'user-managed'
<table:column id="c_com_mypackage_examino_domain_ExamModule_examId" property="myExamId" z="user-managed="/>