1
votes

I have an Xpage with a djTabContainer and the tab container holds several Custom Controls. One of the Custom Controls only has the contents rendered upon meeting a certain condition as shown here;

<xp:this.rendered><![CDATA[#{javascript:getComponent("conCapRev").getValue()   
== "External”}]]></xp:this.rendered>

I want to have the Custom Controls contents rendered now upon meeting one of two conditions, where basically the rendering tag has an or in the Javascript. If this is not possible can there be two rendering tags?

I should mention that the rendering (or not rendering) of the tabbed Custom Control should occur when the document is being created and not just after it has been created and saved.

The code above works for this scenario. When I change getComponent for document1 as shown in the next XML tag it also works with no errors.

<xp:this.rendered><![CDATA[#{javascript:document1.getValue("conCapRev")   
== "External"}]]></xp:this.rendered>

But when I add in the second condition as shown below it does not work and the Custom Control is always rendered. How can I solve this please?

<xp:this.rendered><![CDATA[#{javascript:document1.getValue("conCapRev") == "External" 
|| document1.getValue("conTenderType") != "Extension"}]]></xp:this.rendered>

To perhaps add more information to make the issue clearer - during the initiation of a "Contract" document the user decides if the conCapRev field will be "Internal" or "External", then continuing with the Contracts general information the user selects a value for Tender Type (the ConTenderType field) from a possible list one of which is "Extension". The user then completes at least the Workflow tab with many fields and at this point the Contract can be saved or exit (discard without saving). Before or after the Contract is saved the user can go to another tab named Baseline which will NOT be rendered if the conCapRev field is "External" OR the conTenderType field is "Extension".

2
Use always === and !== for comparison in JavaScript to avoid unexpected type conversions. That is not the issue here though...Knut Herrmann
Thanks Knut. This is good informationAJF
Are you sure you have the logic right? Can you update your question with an example of the field contents from a document and what you expect?Per Henrik Lausten
The logic of this application is complicated - overly complicated in fact (and I did not build it and I have never been trained in Xpages). The document being created has a vast amount of fields due to having a tab that is a workflow that covers over 50 fields alone, so to show you the fields being populated would be an enormous input. I will try and elaborate the question above with more information without having to list what would be about 80 fields for a document record being createdAJF
Focus on what is not working. That is: document1.getValue("conTenderType") != "Extension" returns always true. Test only this condition. First, show "conTenderType" item in a computed field. Contains it really "Extension"? Next, if so, add the render condition to the computed field. Is it still visible? Maybe you use an alias for "Extension" internally...Knut Herrmann

2 Answers

0
votes

You can certainly do what you are trying to do. If the two components are actually bound to data source fields, then you should ask the data source for the value instead of the component.

So try this instead (assuming that your data source is called "document"):

<xp:this.rendered><![CDATA[#{javascript:
document.getValue("conCapRev") == "External" 
|| document.getValue("conTenderType") != "Extension"
}]]></xp:this.rendered>
0
votes

You say in your last question's sentence that you want Baseline Custom Control

NOT be rendered if 
the conCapRev field is "External" OR 
the conTenderType field is "Extension"

or to say it the other way

be rendered if 
the conCapRev field is NOT "External" AND 
the conTenderType field is NOT "Extension"

So, your rendering condition should be then

<xp:this.rendered><![CDATA[#{javascript:
    document1.getValue("conCapRev") != "External" &&
    document1.getValue("conTenderType") != "Extension"
}]]></xp:this.rendered>

Update after some commenting:

After changing conTenderType's value you have to partially refresh

  • the conTenderType's listBox
  • the ContractBaselinePanel panel
  • the ContractDetailPanel panel

You can use cascaded CSJS XSP calls to do so. Make sure you don't try to refresh an element which has the rendered property as if it's not rendered it can't be refresh (because it is not there on client side).

<xp:listBox
    id="listBoxConTenderType"
    value="#{document1.conTenderType}">
    <xp:selectItem
        itemLabel="Extension">
    </xp:selectItem>
    <xp:selectItem
        itemLabel="...">
    </xp:selectItem>
    <xp:eventHandler
        event="onchange"
        submit="false">
        <xp:this.script><![CDATA[
           XSP.partialRefreshPost("#{id:listBoxConTenderType}", {
               onComplete: function() {
                   XSP.partialRefreshGet("#{id:ContractBaselinePanel}", {
                      onComplete: function() {
                          XSP.partialRefreshGet("#{id:ContractDetailPanel}", {});
                      } 
                   });
              }
           });]]></xp:this.script>
    </xp:eventHandler>
</xp:listBox>
<xp:panel
    id="ContractBaselinePanel">
    <xp:panel>
        <xp:this.rendered><![CDATA[#{javascript:
            document1.getValue("conCapRev") != "External" &&
            document1.getValue("conTenderType") != "Extension"
        }]]></xp:this.rendered>
        ...your Baseline Custom Control...
    </xp:panel>
</xp:panel>