Passing Variables to java component

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing Variables to java component

adev

Hi All,

Is it possible to pass some values to the java component through ops.
I have to pass the selected values of select1 (dropdown box) to my a method in my java component.
Its not clear to me how do i go about it.

I am using  oxf:java processor to call my java class

Example
<p:processor name="oxf:java">
        <p:input name="config">
            <config sourcepath="." class="MyJava"/>
        </p:input>
        <p:output name="data" id="output-id"/>
    </p:processor>

Now in one of the methods of java I need to pass the string which user has selected in the select1 dropdown box.
Please help.
Reply | Threaded
Open this post in threaded view
|

Re: Passing Variables to java component

fl.schmitt(ops-users)
hi adev,

> Is it possible to pass some values to the java component through ops.
> I have to pass the selected values of select1 (dropdown box) to my a method
> in my java component.
> Its not clear to me how do i go about it.

the documentation describes how to implement a custom processor with
onputs and outputs:

http://www.orbeon.com/ops/doc/processors-java#d210e428
http://www.orbeon.com/ops/doc/reference-processor-api#d216e138

HTH
florian



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Passing Variables to java component

Erik Bruchez
Administrator
In reply to this post by adev
Although that sounds a little dirty, you could also call Java methods  
directly from XPath in XForms. This Saxon documentation applies:

   http://www.saxonica.com/documentation/extensibility/functions.html

If you go the XPL way, then you must:

* Call a submission from XForms
* Declare your XPL in your page flow
* Write the XPL
* Write the Java code using the Java processor

So it is heavier, although this way you implement a real, reusable  
service.

-Erik

On Mar 13, 2008, at 6:27 AM, adev wrote:

>
>
> Hi All,
>
> Is it possible to pass some values to the java component through ops.
> I have to pass the selected values of select1 (dropdown box) to my a  
> method
> in my java component.
> Its not clear to me how do i go about it.
>
> I am using  oxf:java processor to call my java class
>
> Example
> <p:processor name="oxf:java">
>        <p:input name="config">
>            <config sourcepath="." class="MyJava"/>
>        </p:input>
>        <p:output name="data" id="output-id"/>
>    </p:processor>
>
> Now in one of the methods of java I need to pass the string which  
> user has
> selected in the select1 dropdown box.
> Please help.
> --
> View this message in context: http://www.nabble.com/Passing-Variables-to-java-component-tp16025239p16025239.html
> Sent from the ObjectWeb OPS - Users mailing list archive at  
> Nabble.com.
>
>
> --
> You receive this message as a subscriber of the [hidden email]  
> mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Passing Variables to java component

adev
In reply to this post by fl.schmitt(ops-users)
Hi there,

I tried to get input in java from xforms. The links were very helpful.

Still in  my java program I am getting the following errors.

Compilation Errors

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ops\WEB-INF\resources\apps\test/MyClass.java]'
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ops\WEB-INF\resources\apps\test/MyClass.java:54: cannot find symbol
    symbol  : class XPath
    location: class org.orbeon.saxon.xpath.MyClass
    private static final XPath mXPath = DocumentHelper.createXPath("/xsl:user/xsl:username");
                         ^
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ops\WEB-INF\resources\apps\test/MyClass.java:54: cannot find symbol
    symbol  : variable DocumentHelper
    location: class org.orbeon.saxon.xpath.MyClass
    private static final XPath mXPath = DocumentHelper.createXPath("/xsl:user/xsl:username");
                                        ^
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ops\WEB-INF\resources\apps\test/MyClass.java:57: cannot find symbol
    symbol  : variable OrbeonUtil
    location: class org.orbeon.saxon.xpath.MyClass
            mXPath.setNamespaceURIs(OrbeonUtil.NAMESPACE_MAP);
                                    ^
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ops\WEB-INF\resources\apps\test/MyClass.java:70: cannot find symbol
    symbol  : class User
    location: class org.orbeon.saxon.xpath.MyClass
            User user = MyClass.execute(username);
            ^
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ops\WEB-INF\resources\apps\test/MyClass.java:70: cannot find symbol
    symbol  : method execute(java.lang.String)
    location: class org.orbeon.saxon.xpath.MyClass
            User user = MyClass.execute(username);
                               ^
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ops\WEB-INF\resources\apps\test/MyClass.java:71: cannot find symbol
    symbol  : variable OrbeonUtil
    location: class org.orbeon.saxon.xpath.MyClass
            Document returnedDoc = OrbeonUtil.toXml (user);
                                   ^
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ops\WEB-INF\resources\apps\test/MyClass.java:72: cannot find symbol
    symbol  : variable OrbeonUtil
    location: class org.orbeon.saxon.xpath.MyClass
            OrbeonUtil.returnToOrbeon(contentHandler, returnedDoc);
            ^
    7 errors
   

Java Program

package org.orbeon.saxon.xpath;
import org.orbeon.saxon.expr.XPathContextMajor;
import org.orbeon.saxon.trans.XPathException;
import javax.xml.namespace.QName;
import javax.xml.transform.sax.SAXSource;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import java.util.List;
import org.orbeon.oxf.processor.ProcessorInputOutputInfo;
import org.orbeon.oxf.pipeline.api.PipelineContext;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.orbeon.oxf.processor.SimpleProcessor;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;
import org.dom4j.Document;
public class MyClass extends SimpleProcessor {

private static final XPath mXPath = DocumentHelper.createXPath("/xsl:user/xsl:username");
 
    static {
        mXPath.setNamespaceURIs(OrbeonUtil.NAMESPACE_MAP);
    }

    public MyClass() {
        addOutputInfo(new ProcessorInputOutputInfo(OUTPUT_DATA));
        addInputInfo(new ProcessorInputOutputInfo(INPUT_DATA));  // This is a static const for the string "data". See XPL.
    }

    public void generateData(PipelineContext context, ContentHandler contentHandler)
              throws SAXException
    {
        Document inputDoc = readInputAsDOM4J(context, INPUT_DATA);
        String username = mXPath.selectSingleNode(inputDoc).getStringValue();
        User user = MyClass.execute(username);
        Document returnedDoc = OrbeonUtil.toXml (user);
        OrbeonUtil.returnToOrbeon(contentHandler, returnedDoc);
    }
       
}

XPL

<p:processor name="oxf:xslt" >
        <p:input name="config">
            <xsl:user xsl:version="2.0">
                <xsl:username>
                    <xsl:value-of select="/main/unique"/>
                </xsl:username>
            </xsl:user>
        </p:input>
        <p:output name="data" id="getuserInput" />
    </p:processor> 

    <p:processor name="oxf:java">
        <p:input name="config">
            <config sourcepath="." class="MyClass"/>
        </p:input>
        <p:input name="data" href="#getuserInput" />
        <p:output name="data" id="xml-response" /> 
    </p:processor>
       
       
         <p:processor name="oxf:xml-serializer">
            <p:input name="data" href="#xml-response"/>
            <p:input name="config">
                <config>
                    <content-type>application/xml</content-type>
                </config>
            </p:input>
        </p:processor> 

I am not very much into java but it seems to be related to so import issue. I am using Orbeon 3.6.
Thanks in advance.


fs(ops-users) wrote
hi adev,

> Is it possible to pass some values to the java component through ops.
> I have to pass the selected values of select1 (dropdown box) to my a method
> in my java component.
> Its not clear to me how do i go about it.

the documentation describes how to implement a custom processor with
onputs and outputs:

http://www.orbeon.com/ops/doc/processors-java#d210e428
http://www.orbeon.com/ops/doc/reference-processor-api#d216e138

HTH
florian



--
You receive this message as a subscriber of the ops-users@ow2.org mailing list.
To unsubscribe: mailto:ops-users-unsubscribe@ow2.org
For general help: mailto:sympa@ow2.org?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: Passing Variables to java component

fl.schmitt(ops-users)
hi adev,

> C:\Program Files\Apache Software Foundation\Tomcat
> 5.5\webapps\ops\WEB-INF\resources\apps\test/MyClass.java]'
>     C:\Program Files\Apache Software Foundation\Tomcat
> 5.5\webapps\ops\WEB-INF\resources\apps\test/MyClass.java:54: cannot find
> symbol
>     symbol  : class XPath
>     location: class org.orbeon.saxon.xpath.MyClass
>     private static final XPath mXPath =
> DocumentHelper.createXPath("/xsl:user/xsl:username");

you're using the class XPath, but this class is neigther declared nor
imported. So the compiler can't find it:

http://faculty.capitol-college.edu/~jaanderson/JEMT/cannotFindSymbolClass.html

To persuade the compiler to use the classes, you first have to find the
class and then to import it. XPath and DocumentHelper belong to DOM4J,
so one can import them explicitly using:

import org.dom4j.DocumentHelper;
import org.dom4j.XPath;

This is done automagically if working with an IDE like eclipse, for
example - the imports are managed by default if the classpath is set
correctly (but you have still to be careful - a "XPath" class is
available in some other packages besides DOM4J, too - Xerces, for
example. So in certain cases, you have to choose the correct class from
a list of different classes with the same name).

HTH
florian





--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws