0

I am new in programming and ofbiz. I need to call service that needs parameters from ftl file in javascript function, i want to pass parameters(resiNumber,shipmentId) to that service and call that service. I have try with window.location but i am got: "The data should be encrypted by making it part of the request body (a form field) instead of the request URL"

Here is my ftl code:

<script language="JavaScript" type="text/javascript">
    var ListShipmentId=[];
    function removeShipment(index){

        array.splice(index, 1);
    }

    function iterateList()
    {
        for(index=0;index<ListShipmentId.length;index++)
        {
            alert(ListShipmentId[index]);
        }
    }

    function insertResiNumbers()
    {
        var resi = document.getElementById('noResi').value;
        alert(resi);

        for(index=0;index<ListShipmentId.length;index++)
        {
            window.location = "<@ofbizUrl>updateShipmentResiNumber</@ofbizUrl>?shipmentResiNumber=resi&shipmentId=ListShipmentId[index]";
            alert('kya');
        }
    }


</script>
<div class="screenlet">
  <div class="screenlet-title-bar">
    <h3>${uiLabelMap.PageTitleEditShiping}</h3>
  </div>
  <div class="screenlet-body">
      <input type="hidden" name="_useRowSubmit" value="Y"/>
      <input type="hidden" name="_checkGlobalScope" value="Y"/>
      <table cellspacing="0" class="basic-table">
        <tr class="header-row">
          <td><b>${uiLabelMap.shipmentId}</b></td>
          <td><b>${uiLabelMap.shipmentTypeId}</b></td>
          <td><b>${uiLabelMap.statusId}</b></td>
          <td><b>${uiLabelMap.shipmentNumber}</b></td>
          <td><b>${uiLabelMap.CreatedDate}</b></td>
          <td><b>${uiLabelMap.lastModifiedDate}</b></td>
          <td><b>${uiLabelMap.partyIdTo}</b></td>
          <td><b>${uiLabelMap.CommonAll}<input type="checkbox" name="selectAll" value="${uiLabelMap.CommonY}" onclick="javascript:toggleAll(this, 'selectAllForm');highlightAllRows(this, 'shipmentId_tableRow_', 'selectAllForm');"/></b></td>
        </tr>
        <#list shipment as shipment>
            <tr>
            <td>${shipment.shipmentId}</td>
            <td>${shipment.shipmentTypeId}</td>
            <td>${shipment.statusId}</td>
            <td>${shipment.shipmentNumber?default("")}</td>
            <td>${shipment.CreatedDate?default("")}</td>
            <td>${shipment.lastModifiedDate?default("")}</td>
            <td>${shipment.partyIdTo?default("")}</td>
             <td><input type="checkbox" name="_rowSubmit_o_${shipment_index}" value="Y" onclick="javascript:if(this.value=='Y'){ListShipmentId.push('${shipment.shipmentId}');iterateList(); this.value='N';}else{this.value='Y';iterateList();} " /></td>
             </tr>
        </#list>
        </table>
        <tr>
        <input type="hidden" name="_rowCount"></input>
        <td><input type="text" size='20' id='noResi' name='noResi'/></td>
        <td><input type="submit" value="update" onclick="javascript:alert('ii');insertResiNumbers();"/></td>
        </tr>

</div>

And here is my code in controller.xml for services:

<!-- Kevin -->
        <request-map uri="updateShipmentResiNumber">
        <security https="false" auth="true"/>
        <event type="service" path="" invoke="updateShipmentResiNumber"/>
        <response name="success" type="view" value="ShipedbyCustomer"/>
        <response name="error" type="view" value="ShipedbyCustomer"/>
    </request-map>
<!-- Kevin -->

services.xml:

<service name="updateShipmentResiNumber" engine="simple"
        location="component://product/script/org/ofbiz/product/storage/StorageServices.xml" invoke="updateShipmentResiNumber" auth="true">
<description>Update a ProductFeature to Product Application</description>
<attribute name="shipmentResiNumber" type="String" mode="IN" optional="false"/>
<attribute name="shipmentId" type="String" mode="IN" optional="false"/>

StorageServices.xml:

Kevin
  • 1
  • 2
  • You are using `GET Method` to send data to a server and this data will be sent to a service and `OFBiz` does not allow. You have to use `POST Method`. – Rong Nguyen Sep 09 '15 at 09:22
  • It is works, but how to call service more from once?If i am using window location the service only works once, only one element is updated. I want to pass all element of list. How to run the service more from one? Or there is the way to pass list to service? – Kevin Sep 10 '15 at 05:52
  • Try `service-multi` :) – Rong Nguyen Sep 10 '15 at 07:12

2 Answers2

0

You should use Ajax for calling the service, see How to use ajax in ofbiz Forms? for an example. You will also find examples in the OFBiz source.

Community
  • 1
  • 1
0

Xml Forms is similar like ftl so you can use service-multi and create the form to invoke the service

user3582100
  • 121
  • 1
  • 11