Trivial request perhaps, but wishin' I could access DataSource field names statically, e.g.,
My workaround has been to create a Java class of static field name values, which corresponds to a DataSource XML:
I find this approach results in code that is easier to read and update, and ensures field-name integrity throughout the project. For me anyway.
Code:
DataSource dsEmployee = DataSource.get("EMPLOYEE"); ... SelectItem selectName = new SelectItem(dsEmployee.NAME);
Code:
final class EMPLOYEE { // SQL COLUMN NAMES // RATIONALE for this approach, which may appear needlessly convoluted at first: // IF SQL or DataSource Field Names change, the following assignments will throw errors. // This is the desired behavior: We want to be notified of such changes, and adjust here centrally. protected static final String ID = "EMPLOYEE"; private final static DataSource dsEmployee = DataSource.get(ID); protected static final String EMPLOYEE_ID = dsEmployee.getField("EMPLOYEE_ID").getName(); protected static final String AD_ACCOUNT = dsEmployee.getField("AD_ACCOUNT").getName(); protected static final String EMAIL = dsEmployee.getField("EMAIL").getName(); protected static final String NAME = dsEmployee.getField("NAME").getName(); ...
Comment