jsf - Clearing values of a composite component in a reusable form -
i have composite component:
<ui:component xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:cc="http://java.sun.com/jsf/composite" xmlns:a="http://xmlns.jcp.org/jsf/passthrough"> <cc:interface componenttype="compositelocaldate"> <cc:attribute name="value" type="org.joda.time.localdate" shortdescription="the bean value" required="true" /> <cc:attribute name="days" type="java.lang.boolean" shortdescription="add days input question" required="true" /> <cc:attribute name="disabledby" type="java.lang.boolean" shortdescription="disable component" required="false" /> <cc:attribute name="limitfuture" type="java.lang.integer" shortdescription="how many future months allow based on number of days in future. default = all" required="false" /> </cc:interface> <cc:implementation><!-- --><div class="dateinput"> <h:inputtext autocomplete="off" binding="#{cc.day}" id="day" maxlength="2" styleclass="compositeday" disabled="#{cc.attrs.disabledby}" a:placeholder="dd" a:pattern="[0-9]{1,2}" rendered="#{cc.attrs.days}" /> <h:selectonemenu binding="#{cc.month}" id="month" styleclass="compositemonth" disabled="#{cc.attrs.disabledby}"> <f:selectitem itemlabel="month" itemdisabled="true" /> <f:selectitems value="#{dropdownsbean.months(cc.attrs.limitfuture)}" var="item" itemvalue="#{item.name}" itemlabel="#{item.customerdescription}" /> </h:selectonemenu> <h:inputtext autocomplete="off" binding="#{cc.year}" id="year" maxlength="4" styleclass="compositeyear" disabled="#{cc.attrs.disabledby}" a:placeholder="yyyy" a:pattern="[0-9]{4}" /> </div> </cc:implementation>
that used in form:
<cc:compositelocaldate id="dob" value="#{mybean.alist[formbean.selectedindex].dateofbirth}" days="true" />
the form reused several times add more items list. when add button clicked form cleared:
protected void loadnewitem(mybean mybean, formbean formbean){ mybean.add(new person()); formbean.reset(); formbean.setselectedindex(mybean.getalist.size()-1); }
here's formbean reset method:
public void reset(){ name = null; //other code resets members of formbean }
the problem have clearing form when adding person except composite component retains values entered previous person. assume because stored in compositelocaldate
java class:
public abstract class genericcompositelocaldate extends uiinput implements namingcontainer { private uiinput day; private uiinput month; private uiinput year; private static final logger log = logger.getlogger(genericcompositelocaldate.class); @override public string getfamily() { return uinamingcontainer.component_family; } @override public void encodebegin(facescontext context) throws ioexception { if (getvalue() != null && isvalid()) { calendar cal = calendar.getinstance(); cal.settime(((localdate) getvalue()).todate()); month.setvalue(string.valueof(cal.get(calendar.month) + 1)); year.setvalue(string.valueof(cal.get(calendar.year))); boolean checkdays = (boolean) getattributes().get("days"); if (checkdays) { day.setvalue(string.valueof(cal.get(calendar.day_of_month))); } } super.encodebegin(context); } @override public object getsubmittedvalue() { boolean checkdays = (boolean) getattributes().get("days"); return (checkdays ? day.getsubmittedvalue() : "01") + "/" + month.getsubmittedvalue() + "/" + year.getsubmittedvalue(); } @override protected object getconvertedvalue(facescontext context, object submittedvalue) { log.debug("investigate. submittedvalue \"" + submittedvalue + "\""); try { simpledateformat format = new simpledateformat(); format.applypattern("dd/mm/yyyy"); format.setlenient(false); return new localdate (format.parse((string) submittedvalue)); } catch (parseexception e) { return null; } } public uiinput getday() { return day; } public void setday(uiinput day) { this.day = day; } public uiinput getmonth() { return month; } public void setmonth(uiinput month) { this.month = month; } public uiinput getyear() { return year; } public void setyear(uiinput year) { this.year = year; } }
how can clear these values?
Comments
Post a Comment