How to get value from form builder as label of trigger? - orbeon

I'm working on custom control in Orbeon. In form builder, in settings there is a field called buttonName. Its value is supposed to show as a label of button visible in form runner.
I'm moving an old file that supposedly worked on old version of orbeon. I tried changing the way I refer to the value from form builder. Below I show old code, without my changes.
In form builder metadata I have declared input with ref:
<xbl:binding element="fr|custom-input" id="fr-custom-input-binding" xxbl:mode="lhha binding value">
<!-- Orbeon Form Builder Component Metadata -->
<metadata xmlns="http://orbeon.org/oxf/xml/form-builder" xmlns:xf="http://www.w3.org/2002/xforms">
...
<control-details>
<xf:input ref="#buttonName">
...
Further on, there is a var to that binding
<xf:var name="binding" value="xxf:binding('fr-custom-input-binding')"/>
Finally, the reference in form runner:
<xf:trigger class="xbl-fr-custom-input-trigger">
...
<xf:label value="$binding/#buttonName"></xf:label>
</xf:trigger>

You want to access an attribute on the control itself:
<fr:custom-input buttonName="Your value">
This in contract to an attribute that you could have on the element the control is bound to, which is what $binding points to. So $binding/#buttonName is not the right expression to use here. Instead, inside your , you want to have:
<xf:var name="buttonName" xbl:attr="xbl:text=buttonName"/>
Then you can refer in XPath to the value of the attribute as $buttonName.

Related

Orbeon: Constraints on UI Parent Elements

Does Orbeon have a way to provide validation on parents of UI elements? I've been testing it with some files from previous work on a different XForm engine, and I've noticed a difference in the handling of the errors on fields without direct UI inputs.
My instance looks like:
<set>
<value prop="1"/>
<value prop="2"/>
<value prop="3"/>
</set>
My UI section looks like:
<xf:group ref="set">
<h2>set</h2>
<xf:alert>Bigger Error</xf:alert>
<xf:repeat ref="value">
<xf:input ref=".">
<xf:label>Value</xf:label>
<xf:alert>Error</xf:alert>
</xf:input>
</xf:repeat>
</xf:group>
In the other engine, if a constraint such as <xf:bind ref="set" constraint="count(value) gt 3"/> failed, the error in the set group would show up in the UI. Is there a way for Orbeon to have this same behavior, or is that a non-standard implementation that I was unknowingly relying on?
In the case of Orbeon Forms, if you have an xf:group bound to an invalid node, just as for leaf controls, by default, you'll see the red icon with an exclamation point in the UI if you have <xf:alert> for the group.
If you don't have an <xf:alert>, the HTML element corresponding to the group will just have the xforms-invalid class in the DOM, which allows you, with CSS, to style the group in a way appropriate for your use case.

How to find in java that a jsf component has been removed using jquery?

I am bound to remove a primefaces component only from client side. I am using jquery remove() for that.
As I can not set rendered=false from client side, so I am just trying to count or find in backend controller that the removed component is absent. After removing, I inspected the page html and the component is no more in dom. But before and after removing the component, I get the same value of child count (non zero) fetched through FacesContext:
FacesContext.getCurrentInstance().getViewRoot().findComponent("htmlGeneratedComponentId").getChildCount();
I know FacesContext won't know that the element has been removed by some client side script. JSF wouldn't know anything as no communication has been made to JSF and rendered attribute will remain true as checked by:
FacesContext.getCurrentInstance().getViewRoot().findComponent("htmlGeneratedComponentId").isRendered();
Right now, my requirement is that after removing a component using client side script I need to find in my java controller, a way to know that the component has been removed even if the rendered attribute is still true.
Pass that information via an additional request parameter which you could check in the rendered attribute of the component in question.
E.g.
<h:form>
<input type="hidden" id="fooRemovedByClient" name="fooRemovedByClient" />
...
<x:someComponent id="foo" rendered="#{not param.fooRemovedByClient}" />
</h:form>
And let jQuery set it accordingly on remove:
$foo.remove();
$("#fooRemovedByClient").val("true");
Needless to say that this is hacky. You'd better just let jQuery toggle the rendered attribute via a JSF/PrimeFaces ajax call. The <p:remoteCommand> is useful in this.

orbeon forms - date validation

I have got input with date binding
<xf:bind nodeset="ns:date_1" relevant="true()" type="xs:date" />
and Orbeon creates inptut with datepicker, but it also requires me to fill it with date, otherwise it adds xforms-invalid css class.
How can I make it optional not required?
I've already tried adding attribute required="true()", but nothing happens.
I found it:
instead of
type="xs:date"
declare
type="xf:date"

adding attributes to data.xml using xbl component in form builder

How can we send hint of Single-Line Text component, like xml attributes in Orbeon Form Builder to data.xml?
For example:
hint: first-name="Erik" last-name="Bruchez" email="info#orbeon.com"
<?xml version="1.0" encoding="utf-8" ?>
<form>
<contact first-name="Erik" last-name="Bruchez" email="info#orbeon.com" />
</form>
Now send button generate data.xml like :
<contact>
<first-name>Erik</first-name>
<last-name>Bruchez</last-name>
<email>info#orbeon.com</email>
<phone>6505555555</phone>
</contact>
Or maybe is there some ways to define data.xml attributes from Form Builder?
It look to me like you're trying to bind a control to an attribute (/form/contact/#first-name), instead of an element (/form/contact/first-name). You can do this if you write XForms by hand, but not if you're creating the form with Form Builder. With Form Builder, the structure of the XML used to collect the data is automatically created for you by Form Builder.
If this XML needs to go to another system that expects data in a different format, then you can, on submission, implement your own service to which the data is sent, and you can do the transformation in that service, for instance using XSLT.

Use of xi:include in Orbeon

I created a form using Orbeon form builder, and i included in its form instance the content of an xml file using :
<xi:include href="oxf:/path/file.xml" xxi:omit-xml-base="true" />
When i save the form in form builder and edit it, i get a new form, and when i publish it and run it in form runner i get a blank page.
Can you tell me please what's wrong with the xi:include ?
If you want to include the whole content of an external file as the instance, use:
<xforms:instance id="main-model-instance" src="oxf:/path/file.xml"/>
Here we have the model instance xml in external file at /path/file.xml and we are using this file into our form and have named the model instance as id="main-model-instance"
If you need to add part of the instance from external file, then insert that piece dynamically during xforms-model-construct-done event, e.g.:
<xforms:action ev:event="xforms-model-construct-done">
<!-- Extracts the element some-section from file.xml and uses it as the
root element of the fr-form-instance -->
<xforms:insert context="instance('fr-form-instance')"
origin="doc('oxf:/path/file.xml')/root-element/some-section" />
</xforms:action>

Resources