How to get list of all objects in a request

Can someone advice how to get list of all objects in request? I am trying to process data from form but I can’t find the reason why it doesn’t work for me. Maybe I am trying to get data from wrong variables and from this reason I would like to list all the content of the request. Below is snippet of my code:

{{velocity}}
#if("$!request.ConstructionSitesCode.ExtraCostsClass_0_date" != '')
  #set($docName = 'test4')
  #set($targetDocName = "${doc.space}.${docName}")
  #if(!$xwiki.exists($targetDocName) && $xwiki.hasAccessLevel('edit', $xcontext.user, $targetDocName))
    #set($newDoc = $xwiki.getDocument("${doc.space}.${docName}"))
    $newDoc.setTitle('test4')
    $newDoc.setParent(${doc.fullName})
    $newDoc.setContent('{{include document="ConstructionSitesCode.ExtraCostsTemplate"}}')
    #set($newObj = $newDoc.newObject("ConstructionSitesCode.ExtraCostsClass"))
    $newObj.set("date",${request.ConstructionSitesCode.ExtraCostsClass_0_date})
    $newObj.set("technician",${request.ConstructionSitesCode.ExtraCostsClass_0_technician})
    $newObj.set("hourly-rate",${request.ConstructionSitesCode.ExtraCostsClass_0_hourly-rate})
    $newObj.set("km-rate",${request.ConstructionSitesCode.ExtraCostsClass_0_km-rate})
    $newObj.set("duration",${request.ConstructionSitesCode.ExtraCostsClass_0_duration})
    $newObj.set("distance",${request.ConstructionSitesCode.ExtraCostsClass_0_distance})
    $newObj.set("material-costs",${request.ConstructionSitesCode.ExtraCostsClass_0_material-costs})
    $newObj.set("description",${request.ConstructionSitesCode.ExtraCostsClass_0_description})
    $newObj.set("paid-by-customer",${request.ConstructionSitesCode.ExtraCostsClass_0_paid-by-customer})
    $newDoc.save()
    {{info}}Saved{{/info}}
  #elseif("$!targetDocName" != '' && $xwiki.exists($targetDocName))
    {{warning}}The record already exists. Please choose a different name, or [[view the existing server>>$targetDocName {{/warning}}
  #elseif("$!targetDocName" != '') 
    {{warning}}You don't have permission to do the operation{{/warning}}
  #end
#end


  #set ($xdoc=$xwiki.getDocument('ConstructionSitesCode.ExtraCostsTemplate'))
  #set ($xobject = $xdoc.getObject('ConstructionSitesCode.ExtraCostsClass'))
  #set ($xclass = $xobject.xWikiClass)
  #set ($discard = $doc.use($xobject))
{{html clean="false" wiki="true"}}
<div class="panel panel-primary">
      <div class="panel-heading">
        <h3 class="panel-title">Add costs to the project</h3>
      </div>
      <div class="panel-body">

#set($class = 'ConstructionSitesCode.ExtraCostsClass')


<form action="." class="xform">
    <input id="input_test" name="input_test" type="text" value="XX" size="30"/>
  <div class="row">
    #foreach ($property in $xclass.properties)
      #$escapetool.xml($services.model.serialize($xobject.getProperty($property.name).reference))
      #set ($propertyId = "${xclass.name}_${xobject.number}_$property.name")
      ##if ($property.getValue("size")<16)
        <div class="col-lg-6">
        <label for="$escapetool.xml($propertyId)">
          $escapetool.xml($property.translatedPrettyName)
        </label>
        $doc.display($property.name, 'edit', $xobject)
      </div>
      ##$escapetool.xml($xobject.getProperty($property.name).reference)
    #end
  </div>
  <button type="submit" class="btn btn-primary">Add</button>
</form>

</div>
</div>
{{/html}}

{{/velocity}}

Do you want this

{{groovy}}
  params = request.getParameterNames()
    print "|=request.???|=Value\n"
    params.each {println "|##request."+it + "##|{{code language='text'}}"+request.getParameterValues(it)+"{{/code}}"  }
{{/groovy}}

or 

{{velocity}}
#set ($params=$request.getParameterNames())
|=request.???|=Value
#foreach ($it in $params)
#set ($value=$request.getParameterValues($it))
|request.$it|{{code language="text"}}$value{{/code}}}
#end
{{/velocity}}
1 Like

Thanks a lot, sir. You saved my life!