Catching save event in Form Builder - orbeon

I would like to send submission after form has been saved in Form Builder, I was trying something like this at first (in my XBL file):
<xf:action ev:event="fr-data-save-done" ev:observer="fr-form-model">
<xf:message event="#all" level="modal">Saved</xf:message>
<xf:send submission="my-submission" ev:event="#all"/>
</xf:action>
The code above is placed in XBL file between xbl:template, outside xbl:model (though I tried to put it inside xbl:model with no luck).
Unfortunately it's not working, after I save my form in Form Builder message is not shown.
Anyone got idea why it's not working?

You could place by hand an event handler like this:
<foo:bar id="my-component-id" bind="my-bind">
<xf:dispatch
event="fr-data-save-done"
observer="fr-form-model"
name="my-custom-event"
targetid="my-component-id"/>
</foo:bar>
The handler doesn't have to be within the element:
<foo:bar id="my-component-id" bind="my-bind"/>
<xf:dispatch
event="fr-data-save-done"
observer="fr-form-model"
name="my-custom-event"
targetid="my-component-id"/>
And inside the XBL component:
<xbl:binding id="my-binding-id" element="foo:bar">
<xbl:handlers>
<xbl:handler event="my-custom-event" phase="target">
... XForms actions here ...
</xbl:handler>
</xbl:handlers>
...
</xbl:binding>

Related

How to do an xforms:insert without the need of xforms:delete at the end?

<xf:action ev:event="xforms-model-construct">
<xf:insert nodeset="instance('subInstance')/type" origin="instance('defaultType')/type"/>
</xf:action>
I want to populate an instance based on another one. I can do this using xf:insert as shown above.
However, I realised that the instance 'subInstance' must contain an empty type element before starting the xf:inserts.
<subInstance>
<type/>
</subInstance>
So after all the xf:inserts, I need do the following to delete the first empty one:
<xf:delete nodeset="instance('subInstance')/type" at="1" />
Is there something wrong with this method or is there a way I can insert directly without an initial empty ?
Two answers:
You don't really need an initial type element
Your original instance can simply be:
<subInstance/>
And then you can insert into the subInstance element with:
<xf:action ev:event="xforms-model-construct">
<xf:insert
context="instance('subInstance')"
origin="instance('defaultType')/type""/>
</xf:action>
Using context without nodeset or ref says that you want to insert into the node pointed to by context.
You can still do what you want but with XForms 2.0 support
If you want to keep the original nested type element, you could write this:
<xf:action ev:event="xforms-model-construct">
<xf:insert
nodeset="instance('subInstance')"
origin="
xf:element(
'subInstance',
instance('defaultType')/type
)
"/>
</xf:action>
By targeting the root element of the destination instance, the entire instance will be replaced. This is already the case with XForms 1.1.
With the origin attribute's use of the xf:element() function from XForms 2.0, you can dynamically create an XML document rooted at subInstance and containing only the type elements from the defaultType instance.
To make this even more modern, you would replace nodeset with ref, as nodeset is deprecated in XForms 2.0:
<xf:action ev:event="xforms-model-construct">
<xf:insert
ref="instance('subInstance')"
origin="
xf:element(
'subInstance',
instance('defaultType')/type
)
"/>
</xf:action>

Orbeon disable custom submit to external webservice after submit

How can I disable a custom submit button after submit?
Below you can find my part of code to send:
<xf:trigger bind="booking-bind" id="booking">
<xf:label>
<xh:span>
<xf:output value="'Send'"/>
</xh:span>
</xf:label>
<xf:action ev:event="DOMActivate">
<xf:setvalue ref="instance('fr-form-instance')/submission_type">SendBooking</xf:setvalue>
<xf:setvalue ref="instance('fr-form-instance')/submission_extra_info">//booking[1]</xf:setvalue>
<xf:action type="xpath" xmlns:process="java:org.orbeon.oxf.fr.process.SimpleProcess">
process:runProcessByName('oxf.fr.detail.process', 'send')
</xf:action>
</xf:action>
</xf:trigger>
I am using this solution: Orbeon upgrade from 3.9 to 4.5 : Customized submit for saving forms
I see your trigger has a booking-bind bind. You could have a readonly MIP saying whether the button should be readonly. For example:
<bind id="booking-bind" readonly=". = 'sent'"/>
Then, in your action, do:
<xf:setvalue ref="xxf:bind('booking-bind')" value="'sent'"/>
This will cause the trigger to become readonly.
By the way we have an issue to tackle this better.

Event 'onsave' in rich:editor doesn't fire

I'm implementing some kind of frontend editor in my web page, using rich:editor. When clicking a link, the editor should open, and after saving editor's content, the editor should close again. I'm having trouble with onsave event for closing the editor. Here is my code.
This is the link that opens the editor, due to setting the property bean.show to true. It works ok:
<h:commandLink>
...
<f:setPropertyActionListener value="true" target="#{bean.show}" />
</h:commandLink>
This is the editor itself, only rendered when show evaluates to true:
<h:form>
<rich:editor value="..." onsave="showEditor(false)" rendered="#{bean.show}" />
</h:form>
The onsave event should close the editor by setting the show property to false again, but the editor stays open, because showEditor() is not called:
<a4j:jsFunction name="showEditor">
<a4j:param name="param1" assignTo="#{bean.show}" />
</a4j:jsFunction>
Am I doing something completely wrong? Or do you have any other ideas how to realize this? Any help is appreciated.
just double-checked: in version richfaces 4.x, there is no onsave attribute at all, but
oninit
onblur
onfocus
ondirty
onchange
like pointed out in the org.richfaces.component.UIEditor class. The same is true, if you want to use f:ajax to ajaxify the editor.
Right now, the "save"-icon in the editor just sends a form.submit() or something. So either try to add your jsFunction on that event or to introduce an own save-button.
Edit: Richfaces 4 uses the javascript based CKEditor, so if you want to overwrite their "save"-button, this forum entry regarding CKEditor's save implementation might be of your help.
Also a valueChangeListener might be a possibility solution to trigger your Bean.setShow(boolean show) property.
xhtml:
<rich:editor value="#{bean.editorValue}"
valueChangeListener="#{bean.valueChanged}" />
method in managed bean:
public void valueChanged(ValueChangeEvent e) {
// do the code to close the window here
}
The valueChangeListener also works in Richfaces 4.3, but maybe starting within the javascript of the CKEditor is the better choice.
Hope, that helps... L.

Custom XBL component for submitting form

I'm trying to implement a custom xbl component to submit the form to an external service, perform validation and handle the validation results. The version of orbeon is 4.4-CE deployed on JBoss 7.1.1.Final with MySQL persistence layer.
<xbl:binding element="fr|custom-submit" id="fr-custom-submit" xxbl:mode="lhha binding value">
<xbl:implementation>
<xf:model id="custom-submit-model">
<xf:instance id="validation-res">
<dummy/>
</xf:instance>
<!-- External validation submission -->
<xf:submission id="form-submission" ref="instance('fr-form-instance')"
action="http://localhost:8080/webapp/services/task/submitData" method="post"
replace="instance" instance="validation-res">
<xf:delete ev:event="xforms-submit" ref="//#v:*"/>
<xf:action ev:event="xforms-submit-done">
<!-- Insert external validation results when done -->
<xf:insert ref="." origin="instance('validation-res')/v:data/*"/>
<!-- Handle the valid/invalid result -->
</xf:action>
</xf:submission>
</xf:model>
</xbl:implementation>
<xbl:template>
<fr:button ref="xxf:binding('fr-custom-submit')">
<xf:label>
<xh:img src="/apps/fr/style/images/silk/disk.png"/>
<xh:span>Custom save</xh:span>
</xf:label>
<xf:send ev:event="DOMActivate" submission="form-submission"/>
</fr:button>
</xbl:template>
</xbl:binding>
Upon submitting the form the following exception occurs in the log files:
Empty single-node binding on xf:submission for submission id: form-submission |
I cannot figure out, what the exception means and if the cause of the problem is the strong encapsulation as described here.
Is it in general possible to write a custom xbl component for submitting a form? How can I overcome the above mentioned problem?
Regards
It is indeed an issue related to encapsulation, and using xxf:instance() allows you to break the encapsulation. So in your case, the submission would do:
ref="xxf:instance('fr-form-instance')"

XPages add form tag to disable Ajax

I'm using jQuery Mobile (1.2.0) and XPages (8.5.3) and want to disable the Ajax form submission as this appears to be preventing an image being saved (all other text fields are saved successfully).
Can I add data-ajax="false" to the form tag using the following?
<xp:this.attrs>
<xp:attr name="data-ajax" value="false"></xp:attr>
</xp:this.attrs>
I tried using Form in Themes (as per adding styleClass) but nothing was added, I could add the styleClass.
Just add these lines to your theme:
<control mode="override">
<name>Form</name>
<property>
<name>attrs</name>
<complex type="xp_attr">
<property>
<name>name</name>
<value>data-ajax</value>
</property>
<property>
<name>value</name>
<value>false</value>
</property>
</complex>
</property>
</control>
Another alternative to this can be setting the createForm property in XPages to false. This would not generate form tag and allow you to create your own using xp:form. Then you can add your custom attribute using xp:this.attrs just like you did in your query. So you code would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" createForm="true">
<xp:form id="myForm">
<xp:this.attrs>
<xp:attr name="data-ajax" value="false"></xp:attr>
</xp:this.attrs>
<!-- All the other controls go here -->
</xp:form>
</xp:view>
This would generate the form tag looking something like this:
<form id="view:myForm" method="post" action="/myPath/myDatabase.nsf/xFormAttrs.xsp" class="xspForm" enctype="multipart/form-data" data-ajax="false">

Resources