xpages - How to reverse the order of evaluation in partial update? -
xpages - How to reverse the order of evaluation in partial update? -
i have encountered when using onchange event on field partial update set, execution of partial update performed before ssjs-code on actual event.
is there possible way reverse this?
in enclosed illustration have 3 fields, 1 hidden input , computed value.
users enters values in these 3 fields , hidden component has formula calculate sum of fields above. nominal * cost + fee = paymentamount. client wants have predefined fee value gets calculated before paymentamount; in illustration utilize hardcoded value of 0.15%. formula paymentamount = (nominal * cost * feedef) + (nominal*price)
we have set paymentamount within table have tagged row paymentamountrow able update both components within. components used have partial update on paymentamountrow need component cost update fee1 well. thought if changed partial update component above everything, in case surrounding panel called dealinfo work fine surprise calculation of partial component triggered before actual code calculates fee.
i have tried available parameters on event none of them working…
<?xml version="1.0" encoding="utf-8"?> <xp:view xmlns:xp="http://www.ibm.com/xsp/core"> <xp:this.resources> <xp:script src="/commonssjs.jss" clientside="false" > </xp:script> </xp:this.resources> <xp:panel id="dealinfo"> <xp:this.data> <xp:dominodocument var="document1" formname="equitytrade" > </xp:dominodocument> </xp:this.data> <xp:label value="nominal" id="label2" > </xp:label> <xp:inputtext id="nominal" value="#{document1.nominal}" > <xp:eventhandler event="onchange" submit="true" refreshmode="partial" refreshid="paymentamountrow" > <xp:this.action><![cdata[#{javascript:print("nominal onchange - partial paymentamount");}]]></xp:this.action> </xp:eventhandler> <xp:this.converter> <xp:convertnumber type="number"></xp:convertnumber> </xp:this.converter> </xp:inputtext> <xp:br></xp:br> <xp:label value="price" id="label1" > </xp:label> <xp:inputtext id="price" value="#{document1.price}" > <xp:this.converter> <xp:convertnumber type="number"></xp:convertnumber> </xp:this.converter> <xp:eventhandler event="onchange" submit="true" refreshmode="partial" refreshid="fee1"> <xp:this.action><![cdata[#{javascript:print("price onchange - update") var fee1:com.ibm.xsp.component.xp.xspinputtext = getcomponent("fee1"); var feedef = 0.15; var nominal:com.ibm.xsp.component.xp.xspinputtext = getcomponent("nominal"); var price:com.ibm.xsp.component.xp.xspinputtext = getcomponent("price"); var fee = nominal.getvalue()*price.getvalue()*feedef fee1.setvalue(fee); }]]></xp:this.action> </xp:eventhandler> </xp:inputtext> <xp:br></xp:br> <xp:label value="fee 1" id="label3" > </xp:label> <xp:inputtext id="fee1" value="#{document1.fee1}" > <xp:this.converter> <xp:convertnumber type="number"></xp:convertnumber> </xp:this.converter> <xp:this.valuechangelistener><![cdata[#{javascript:print("value changed"); }]]></xp:this.valuechangelistener> <xp:eventhandler event="onchange" submit="true" refreshmode="partial" refreshid="paymentamountrow" ></xp:eventhandler> </xp:inputtext> <xp:br></xp:br> <xp:table> <xp:tr id="paymentamountrow"> <xp:td> <xp:inputhidden id="paymentamount" value="#{document1.paymentamount}" > <xp:this.converter> <xp:customconverter getasstring="#{javascript:return value.tostring();}"> <xp:this.getasobject><![cdata[#{javascript:try { print("paymentamount calculation"); var nominal:com.ibm.xsp.component.xp.xspinputtext = getcomponent("nominal"); var price:com.ibm.xsp.component.xp.xspinputtext = getcomponent("price"); var fee1:com.ibm.xsp.component.xp.xspinputtext = getcomponent("fee1"); var nominal = nominal.getvalue(); var cost = price.getvalue(); var fee1= fee1.getvalue(); var paymentamount = nominal * price; paymentamount+=fee1; homecoming paymentamount; } catch(e){ dbar.info(e); }}]]></xp:this.getasobject> </xp:customconverter> </xp:this.converter> </xp:inputhidden> <xp:text escape="true" id="computedfield14" > <xp:this.value><![cdata[#{document1.paymentamount}]]></xp:this.value> <xp:this.converter> <xp:convertnumber type="number"></xp:convertnumber> </xp:this.converter> </xp:text> </xp:td> </xp:tr></xp:table> </xp:panel> </xp:view>
i'm not 100% sure understand code or part causing problem, think it's converter's getasobject() running before application logic of eventhandler , not getting right values. here goes:
xpages (and jsf) partial refresh lifecycle runs through 6 phases: 1) restore view rebuilds component tree can map html beingness sent underlying java objects. 2) apply request values takes string values entered in html , puts them in submittedvalue property of each relevant component. 3) process validation runs converters , validators ensure submittedvalue properties can converted underlying info type , pass validation rules defined on server. 4) update model values takes submittedvalues (now know can apply them info model without screwing things up!), converts strings relevant datatype, puts them in value property , sets submittedvalue null. (it might have converted strings during process validation phase , stored them in internal variables, needs update value , submittedvalue @ phase, not sure.) 5) invoke application runs eventhandler logic. 6) render response generates updated html browser.
you can't alter order. process validations has run before update model values. otherwise, update model values break because info type's wrong, or you've stored invalid value written underlying document.
i think problem you're converter using getcomponent().getvalue(). value won't have been set during process validations phase, when converter's getasobject() method running.
if so, need either:
to utilize getcomponent().getsubmittedvalue(), validate values of other components in converter, , throw errors accordingly.or
just utilize basic number converter , move code setting payment amount eventhandler, interacting backend info - getting document1.price etc , setting document1.paymentamount.if utilize latter, should able avoid needing inputhidden.
xpages lotus
Comments
Post a Comment