W3C home > Mailing lists > Public > www-forms@w3.org > March 2007

Integrating XForms & JSF - a tip

From: Adam Flinton <adam.flinton@nhs.net>
Date: Wed, 07 Mar 2007 10:51:37 +0000
Message-ID: <45EE9939.3060801@nhs.net>
To: Www-Forms Www-Forms <www-forms@w3.org>

Dear All,

I have an XForm (either native (e.g. in firefox) or rendered to html by 
Chiba within a larger page made up by & controlled by JSF.

So quick tip time:

On the XForm submit trigger/action , add a sub-action which uses post 
submit-done to call a javascript method called 
clickLinkByClass('Refresh','input') e.g.

    <xforms:trigger id="OID_Group_trigger" style="display:block">
        <xforms:label>Update</xforms:label>
        <xforms:action ev:event="DOMActivate">
            <xforms:send submission="xmlprocess" />
            <xforms:action ev:event="xforms-submit-done" propagate="false">
                <xforms:load
                    
resource="javascript:clickLinkByClass('Refresh','input')" />
            </xforms:action>
        </xforms:action>
    </xforms:trigger>



The JS is:

function clickLinkByClass(Classname,tagname){

    var targetE1;
    myObjCol = getElementsByClassName(Classname, tagname);
    if (myObjCol != null && myObjCol.length > 0){
        for (i = 0, j = myObjCol.length; i < j; i++) {
            targetE1 = myObjCol[i];
            }
        //var targetID1 = targetE1.id;
        if (document.createEvent)
    {
        var evObj = document.createEvent('MouseEvents')
        evObj.initEvent( 'click', true, false )
        targetE1.dispatchEvent(evObj)
    }
    else if (document.createEventObject)
    {
        targetE1.fireEvent('onclick')
    }  
}
}


Then on your main jsf (i.e. the one which includes the XForm) place a 
button action which simply calls an empty method on the Backing bean e.g.

    <h:form id="RefreshForm" rendered="true">

        <h:inputHidden id="XMLFile" value="#{DisplayController.xmlFile}" />
        <h:inputHidden id="editState" 
value="#{DisplayController.editState}" />
        <h:inputHidden id="type" value="xform" />
        <h:inputHidden id="JavaScriptYN" value="" />

        <h:panelGrid columns="1">

            <h:commandButton id="Refresh" value="Refresh"
                action="#{DOMElement.refresh}" styleClass="Refresh">
                <t:updateActionListener property="#{DOMElement.init}"
                    value="#{DisplayController.xmlFile}" />
                <t:updateActionListener property="#{DOMElement.nodeLocator}"
                    value="#{DOMElement.nodeLocator}" />
            </h:commandButton>
        </h:panelGrid>

    </h:form>


Then hide it from view via css e.g.

input.Refresh{display:none; visibility: hidden;}   

et voila when the XForm submits, the JSF is refreshed.

Adam

**********************************************************************
Information in this message  may contain  confidential and  privileged
information.  If you are not  the intended recipient please accept our
apologies; please do not disclose,  copy or distribute  information in
this e-mail or take any  action in reliance on its  contents: to do so
is strictly prohibited and may be unlawful. Please inform us that this
message  has  gone  astray  before  deleting it.  Thank  you for  your
co-operation.
 
NHSmail is used daily by over 100,000 staff in the NHS. Over a million
messages  are sent every day by the system.  To find  out why more and
more NHS personnel are  switching to  this NHS  Connecting  for Health
system please visit www.connectingforhealth.nhs.uk/nhsmail 
**********************************************************************
Received on Wednesday, 7 March 2007 17:06:37 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:22:09 GMT