jsf - Auto calculated fields -
i've following form:
<h:form> <h:inputtext size="2" value="#{ordermb.quantity}" /> <h:outputlabel value=" #{ordermb.totalpriceoneitem} €" /> <h:commandbutton value="submit" /> </h:form> and i've following method in session scoped managed bean:
public void setquantity(int quantity) { this.quantity = quantity; settotalpriceoneitem(quantity* item.getitem().getprice().doublevalue()); } i auto-update total price result on every key press of input field. how can achieve without pressing submit button?
your code isn't doing anywhere. it's missing <f:ajax>.
<h:inputtext size="2" value="#{ordermb.quantity}"> <f:ajax event="keyup" render="total" /> </h:inputtext> <h:outputtext id="total" value="#{ordermb.totalpriceoneitem} €" /> the event attribute can set html dom event on jsf must submit form ajax, such click, keyup, blur, focus, etc. render attribute can set jsf client id needs updated when ajax submit finishes. in case it's referring id of component showing total price.
note replaced wrong <h:outputlabel> <h:outputtext>. noted should setter isn't right place perform business logic (a getter not!). better revert setter method true setter , add ajax listener method:
<f:ajax event="keyup" listener="#{ordermb.updatetotalpriceoneitem}" render="total" /> public void updatetotalpriceoneitem() { totalpriceoneitem = quantity * item.getitem().getprice().doublevalue(); } in case when still doesn't work, verify if have <h:head> in template instead of <head>. if still in vain, work through commandbutton/commandlink/ajax action/listener method not invoked or input value not updated.
that said, recommend take pause , work through sane jsf 2.x book. above covered in 1st chapter.
Comments
Post a Comment