java - How to prevent JSF namespace pollution -
i consider jsf have namespace pollution in have expose private members world shouldn't do.
here's example:
suppose have form data , date input forms, represented in backing beans as:
private date fromdate; private date todate; // getters , setters jsf xhtml page can see fields , work 'em
then have private method, being called on post construct:
private list<? extends statisticsmodel> _getdatamodel() { list<? extends statisticsmodel> datamodel = null; if (issingledate()) { datamodel = getdatamodel(getfromdate(), getfromdate(), getselected()); } else { datamodel = getdatamodel(getfromdate(), gettodate(), getselected()); } return datamodel; }
which calls abstract method every subclass have implement:
protected abstract list<? extends statisticsmodel> getdatamodel(date from, date to, string[] selected);
if carefully, find abstract method from date
, to date
parameters critical , differ private fields.
but because of jsf, have make private fields of date, public, hence developer -who work on subclasses - confuse ed between dates sent method args , dates inherited public properties super class.
for such case, did workaround appending under score on front private fields names (c trick), think not enough.
edit problem is, in ideal world, fields fromdate , todate should kept private superclass, , knows then, convert , pass them down subclasses (as done in _getdatamodel
method). in jsf, date fields should have getters , setters (to accessible xhtml
pages) , hence accessible subclasses of controller, lead confusion when working on subclasses, because subclass able see 2 from date
vars (1 field + 1 arg), , 2 to date
vars well. (which each pair might have different values). hope clear now!
do think real problem? , how can solve it?
Comments
Post a Comment