How can I refresh the field in CSJS

320 views Asked by At

How to refresh one field in csjs? the code is here:

<xp:repeat id="repeat1" rows="30" var="currentDetail" indexVar="detailIndex" value="#{LeaveBean.details}">
    <xp:inputText id="leavefrom" value="#{currentDetail.subfromtime}">
         <xp:eventHandler event="onblur" submit="false" refreshMode="partial" refreshId="repeat1">
                 <xp:this.script><![CDATA[
                      XSP.partialRefreshPost('#{id:view:_id1:repeat1:0:leavefrom}');
                      var detailIndex = document.getElementById("#{id:detailIndexText}").innerHTML;
                      myRPC.checkfromdate(detailIndex).addCallback(function(returnAlert){alert(returnAlert);});
                 ]]></xp:this.script>
      </xp:eventHandler>
   </xp:inputText>
</xp:repeat>

what I want to do is call ssjs from csjs as you can see, but the strange thing to me is the click thing didn't work immediately, for example, when I first open the page, and click the input field, and enter "1" in it, it should be popup alert just when i left the field, but nothing happend, then I click this field again, and enter "2", then I left the field, but I just got the alert "1" on the secreen...sorry for my poor expressions...

so my question is I should refresh the field just when I left the field immediately, but why the XSP.partialRefreshPost not working? I tried to refresh repeat1, not working either

update 2015/06/13: At last, I found view.postScript....so....

1

There are 1 answers

2
Paul Stephen Withers On BEST ANSWER

One obvious problem is the partialRefreshPost id won't work. You're combining #{id:...} which runs server-side to calculate the corresponding client-side ID. But the ID that you're passing is a client-side ID for the first row of the repeat. Even if that corresponded to a server-side component, you're trying to hard-code every row to map to a field in row 1 of the repeat ("repeat1:0").

Is there a reason for not using a normal partial refresh and using view.postScript in your SSJS to post CSJS back to the browser? You're triggering a partial refresh posting data back anyway. I'm not sure what the final line of your code is doing, but it seems like it's calling another server-side request to add a response. So the code seems to do two calls to the server, to trigger an alert. I don't know the design and what that subsequent rpc call is doing, but if it can be achieved in a single partial refresh, that would seem better.