another familiar question
If I want to do the same sumary in the amt field I wrote
      <fd:on-value-changed>
         <javascript>
          var dList =  event.source.parent.lookupWidget("daily1List");
          var testv=new Packages.java.math.BigDecimal("0");

          for (var i = 0; i &lt; dList.size; i++) {
                var row = dList.getRow(i);
 var num1 = new
Packages.java.math.BigDecimal(row.lookupWidget("amt").getValue());
 testv = testv.add(num1);
        }
        var test = event.source.parent.lookupWidget("test");
        test.setValue(testv);
       </javascript>
       </fd:on-value-changed>
But the system say can't convert Null to object,why

Best Regards

Johnson


----- Original Message ----- 
From: "Bruno Dumon" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 18, 2004 2:46 PM
Subject: Re: the widget datatype question


> On Fri, 2004-06-18 at 08:33, Johnson wrote:
> > Hi
> >
> >  I try to caculate the widget value in repeter to another widget,the
code is
> >
> >      <fd:field id="test">
> >        <fd:label><i18n:text key="test">test:</i18n:text></fd:label>
> >        <fd:datatype base="decimal"/>
> >      </fd:field>
> >
> >      <fd:repeater id="daily1List">
> >        <fd:field id="amt">
> >          <fd:label><i18n:text key="amt">amt:</i18n:text></fd:label>
> >          <fd:datatype base="decimal"/>
> >        </fd:field>
> >      </fd:repeater>
> >
> >      <fd:repeater-action id="removeDaily1" action-command="delete-rows"
> >  repeater="daily1List" select="select">
> >            <fd:label><i18n:text
> >  key="removeDaily1">removeDaily1:</i18n:text></fd:label>
> >           <fd:on-activate>
> >           <javascript>
> >            var dList =  event.source.parent.lookupWidget("daily1List");
> >            var testv=0;
> >
> >            for (var i = 0; i &lt; dList.size; i++) {
> >                  var row = dList.getRow(i);
> >                  num1 = row.lookupWidget("amt").value;
> >                  testv = testv + num1;
> >          }
> >
> >          var test = event.source.parent.lookupWidget("test");
> >          test.setValue(testv);
> >         </javascript>
> >        </fd:on-activate>
> >
> >      </fd:repeater-action>
> >
> >  If I had two row,one amt is 1,one amt is 2,the test will be "12",why.
>
> Probably because Javascript doesn't know about bigdecimals. Depending on
> your needs, you could change the datatype of the widget to float, double
> or long.
>
> If you need the precission of bigdecimal numbers, you need to use the
> methods of the BigDecimal class to do your calculations. See the javadoc
> of that class.
>
> It would be something like
>
> var testv = new Packages.java.math.BigDecimal("0");
> testv = testv.add(num1);
>
> -- 
> Bruno Dumon                             http://outerthought.org/
> Outerthought - Open Source, Java & XML Competence Support Center
> [EMAIL PROTECTED]                          [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to