Display only 1 field in Nested Object Metawidget

271 views Asked by At

Using the metawidget to build some flexible UI in Java: https://sourceforge.net/projects/metawidget/

public class Cohort  {

    private int id;
    private Project project;
    private Member teamLead;

    public Cohort() {   }

    @UiHidden
    public int getId() { return id; }
    public void setId(int id) { this.id = id; }

    public Project getProject() { return project;   }
    public void setProject(Project project) { this.project = project; }

    public Member getTeamLead() { return teamLead; }
    public void setTeamLead(Member teamLead) { this.teamLead = teamLead; }

}

Cohort is the class inspected. However as is desirable it recursively inspects both the Project and Member classes.

When displayed on the UI, it will display all the fields for each of the classes. However I would only like to display the "Name" field of the Project and firstName + last Name of the Member.

1

There are 1 answers

4
Richard Kennard On BEST ANSWER

There are a number of ways to achieve this. I'll start with one and let me know if it's sufficient for your needs:

a) mark the fields of Project/Member that you don't want to see as UiHidden (you don't say what those fields are, but you seem to have gotten the idea because you are already hiding 'Cohort.getId'). Note you can also reuse existing annotations (like JPA annotations) for this purpose.

b) mark 'Cohort.getProject' and 'Cohort.getTeamLead' as UiLabel( "" ). This will suppress the sub-label for the sub-object, and make its fields appear as if part of the original object.