Live page questions

Hi!

Once again I ask for help, I can not solve the problem myself.

Required:
When editing a page depending on the values in List1, dynamically generate List2
List 1:

{{velocity}}
#if($context.action == 'edit') 

  {{html wiki="true"}}
  <select id="List1">
    <optgroup label="Group1">
      <option>Item11</option>
      <option>Item12</option>
      <option>Item13</option>
      <option>Item14</option>
    </optgroup>
    <optgroup label="Group2">
      <option>Item21</option>
      <option>Item22</option>
    </optgroup>
  </select>
    #set($selVal = $request.getParameter('selVal'))
    $doc.set('hdwType', $selVal)
    $doc.save()
  {{/html}}
  
#else

  $value

#end

{{/velocity}}

List 2
Type: Database List based oh HQL Query.
On change event in List1 send the selected value as a parameter in the HQL Query of List2.

Part of JSX Code:

hdwTypeSelect.change(function() {
  sendTypeValue(this.value);
});

function sendTypeValue(typeValue) {
  var UrlParams = {'xpage': 'plain','outputSyntax': 'plain', 'typeValue': typeValue};
    new Ajax.Request(docUrl, {
      parameters: UrlParams,
      onSuccess : function(response) {
        getTypeValue();
      }
    });
  }

  function getTypeValue() {
    /*temporarily hardcoded some values*/
    #set ($document = $xwiki.getDocument('HardwareInventory.testPage1')) 
    #set ($resp = $request.getParameter("typeValue"))
    
    // Questions:

    //  1. How to debug $resp? Alert('$resp') doesn't work.
    //  2. How to access the property 'Hibernate Query'? Is programming rights required?
    //  3. Is implementation correct generally?
  }

Thanks.

Now problem simplified to:

how to access and set the Database List’s property ‘Hibernate Query’? Is programming rights required?

Thanks.

As far as I understand the author of the document containing the class need at least SCRIPT right (that field is actually interpreted as a Velocity script which generate a HQL statement). Then it depend on what you use in the query, the following rules apply: https://extensions.xwiki.org/xwiki/bin/view/Extension/Query%20Module#HAllowedHQL2FXWQLselectqueries.

1 Like

Thanks.
I expect something like:

function setSubTypeValue() {
    #set ($document = $xwiki.getDocument('HardwareInventory.testPage1')) 
    #set ($resp = $request.getParameter("typeValue"))

    // 
    #set ($document.setParameter("hdwSubType")).HQLQueryParam1 = $resp)
    //

How to access the Hibernate Query property of the Database List component in realtime and redefine it?

Thanks.

Well, with plenty of troubles, I discovered that there is no way to realize my idea :frowning:
Realized only one working version by example from mailing list:

{{velocity}}
#set($classDoc = $xwiki.getDocument('HardwareInventory.Code.HardwareInventoryClass'))
#set($propertyDefinition = $classDoc.getxWikiClass().get('hdwSubTypeList'))
## $propertyDefinition.class should now print com.xpn.xwiki.api.PropertyClass
## Unfortunately, at this point you need programming rights to go into the inner, protected property definition
#set($propertyDefinition = $propertyDefinition.getPropertyClass())
## $propertyDefinition.class should now print com.xpn.xwiki.objects.classes.StaticListClass
## If it doesn't, then you don't have programming rights.
$propertyDefinition.setValues('test1|test2|test3|test4|test5')
## Don't forget to save
$classDoc.save('')
{{/velocity}}

But a major disadvantage is that the class is modified, not the document.
Also it will not work for users without programming rights.

I will try to go in another direction: refuse to use *List components. But here’s another problem: I need a columnar filter with multiple choices. Livetable Multilist column type is ideal, but it works only with *List components and doesn’t support String fields.
Are there any tricks to make it work with String fields?
How else can I implement a multifilter with checkboxes in Livetable?

Thanks.

I have not yet advanced in solving the goal.
Who would suggest?

Thanks…

http://xwiki.475771.n2.nabble.com/Dynamic-lists-td510560.html