How to create Orbeon custom control XBL with prede

2019-05-31 08:15发布

问题:

I have created a custom control (hidden text box with some predefined value), where I want to set visibility=false(), controlName="Mycustom", default value="This is my custom control" in XBL file. So that whenever we use that custom control from Orbeon Form Builder, it will come with all default values with no need to set anything.

XBL:

<xbl:xbl xmlns:xh="http://www.w3.org/1999/xhtml"
         xmlns:xf="http://www.w3.org/2002/xforms"
         xmlns:xs="http://www.w3.org/2001/XMLSchema"
         xmlns:ev="http://www.w3.org/2001/xml-events"
         xmlns:xi="http://www.w3.org/2001/XInclude"
         xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
         xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
         xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
         xmlns:saxon="http://saxon.sf.net/"
         xmlns:xbl="http://www.w3.org/ns/xbl"
         xmlns:exf="http://www.exforms.org/exf/1-0"
         xmlns:xxbl="http://orbeon.org/oxf/xml/xbl">

     <metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
        <display-name lang="en">Epson Custom Controls</display-name>
    </metadata>

    <xbl:binding id="fr-custom" element="fr|custom" >
        <metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
            <display-name lang="en">My Custom Control</display-name>
            <icon lang="en">
                <small-icon>/forms/orbeon/builder/images/input.png</small-icon>
                <large-icon>/forms/orbeon/builder/images/input.png</large-icon>
            </icon>
            <templates>
                <bind xxf:whitespace="trim"/>
                <view>
                    <xf:input id="myCustom" ref="" xmlns="">
                       <xf:label>My Custom lable</xf:label>
                        <xf:hint ref=""/>
                        <xf:help ref=""/>
                        <xf:alert ref=""/>
                    </xf:input>
                </view>
            </templates>
        </metadata>
    </xbl:binding>
</xbl:xbl>

Using above control I want hidden text box with value='This is my custom control' and its control name should be Mycustom.

Update

I have tried with below changes, but it is not working

        <templates>
            <bind xxf:whitespace="trim" relevant="false()" xxf:default="'This is my custom control'"/>
            <view>
                <xf:input id="myCustom" ref="" xmlns="">
                   <xf:label>Success Message</xf:label>
                    <xf:hint ref=""/>
                    <xf:help ref=""/>
                    <xf:alert ref=""/>
                </xf:input>
            </view>
        </templates>

With above changes now its working (control is hidden with some default value).

Can you please let me know how to put if condition properties-local.xml:

 <property as="xs:string"  name="oxf.fr.detail.process.save-final-custom.*.*">
            require-uploads
            then validate-all
            then save
            if({xxf:instance('fr-form-instance')//customMessage} != null)
              {
                then success-message(message = "{xxf:instance('fr-form-instance')//customMessage}")
              }
            recover error-message("database-error") 
     </property>

Here I want to override this success-message if it properly configured from backed. If it's value is null then want to show OOTB message(don't override).

Update2

Integrated changes in Hybris. below are the changes I have made in Hybris

  • Create XBL > orbeon > custom > custom.xbl

<bind xxf:whitespace="trim" relevant="false()" xxf:default="'This is my custom control'"/>

Issue :- When we select custom control, it will bind without any lable/message/visibility etc. But if I refresh left control panel then label start appearing on the form. but still default message is not set.

回答1:

Let's take the items you mentioned one by one:

  1. visibility="false()" – I imagine you're referring to the relevant attribute in XForms, instead of the visibility attribute. (Form Builder calls this "visibility", because this is what it is, but in XForms, the attribute is relevant.) This can be done by having inside the <templates> a <bind relevant="false()"/>.
  2. controlName="Mycustom" – You can't set the id of the control in XBL. (BTW, when using Form Builder, the XForms id is inferred from the control name defined by the form author in Form Builder.) The id is set by whoever uses the control, not whoever defines it, otherwise, for one, this would prevent you from having multiple instances of that control in the form.
  3. default value="This is my custom control" – As in #1 above, you can do this with <bind xxf:default="'This is my custom control'">. Note the added single quotes, as the value of xxf:default is an XPath expression.