submitting xforms throw struts

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

submitting xforms throw struts

Jose Gato Lui
Hello all, in my company we are trying to use XForms in our platform
based in struts/jsp.

In this moment I have an XForm form that I want to submit to our
application in this way:

 <xforms:submission id="submitIntercambioTareas"
ref="instance('mainForm')" method="get" replace="instance"
instance="mainForms"
action="http://localhost:9000/opencities/testXForms.do"
separator="&amp;" />

The testXForms.do struts call to an action java class:

<action path="/testXForms"
type="com.andago.opencities.struts.actions.mantenimiento.testXFormsAction"
name="testXFormsForm"
scope="session"
validate="false">
<forward name="success" path="/web/jsp/comun/testXForms.jsp" />
</action>


in this class(testXformsAction) I can access to the complete instance
"mainForm" because I have a java form bean(testXFormsForm) with the same
parameters like the XForm:

form.getFoo();
form.getBar();

Now the problems:

- This only works with get method, because the xforms travels in the
url: http://localhost:9000/opencities/testXForms.do?foo=13&bar=123... If
I use a post method I cannot acces to the form with:
  form.getFoo();

- Using get method If I modified the values of the form in the action
class:

    form.setFoo = 567

  This new values are not refreshed in my XForm instance when the struts
fordward call again my XForm web page.



I know that If I use a get method I will lost the XML structure, but
this is not very important for me.

Sorry for the questions, Im a "newbie" in this technology...

Thanks all...



--
José Gato Luis
Departamento de I+D
Ándago Ingeniería - www.andago.com

Teléfono: +34 916 011 373
e-mail: [hidden email]




--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: submitting xforms throw struts

Erik Bruchez
Administrator
Jose,

 > Hello all, in my company we are trying to use XForms in our platform
 > based in struts/jsp.
 >
 > In this moment I have an XForm form that I want to submit to our
 > application in this way:
 >
 >  <xforms:submission id="submitIntercambioTareas"
 > ref="instance('mainForm')" method="get" replace="instance"
 > instance="mainForms"
 > action="http://localhost:9000/opencities/testXForms.do"
 > separator="&amp;" />
 >
 > The testXForms.do struts call to an action java class:
 >
 > <action path="/testXForms"
 >
type="com.andago.opencities.struts.actions.mantenimiento.testXFormsAction"
 > name="testXFormsForm"
 > scope="session"
 > validate="false">
 > <forward name="success" path="/web/jsp/comun/testXForms.jsp" />
 > </action>
 >
 >
 > in this class(testXformsAction) I can access to the complete instance
 > "mainForm" because I have a java form bean(testXFormsForm) with the same
 > parameters like the XForm:
 >
 > form.getFoo();
 > form.getBar();
 >
 > Now the problems:
 >
 > - This only works with get method, because the xforms travels in the
 > url: http://localhost:9000/opencities/testXForms.do?foo=13&bar=123... If
 > I use a post method I cannot acces to the form with:
 >   form.getFoo();

 > - Using get method If I modified the values of the form in the action
 > class:
 >
 >     form.setFoo = 567
 >
 >   This new values are not refreshed in my XForm instance when the struts
 > fordward call again my XForm web page.

Right, this will not occur automatically!

First, there is a problem with your submission: it says
replace="instance", which means that your submission must return an
XML document. You don't do this, what you do is that you forward the
result of the JSP page that produces the whole XForms page again.

So either:

o Use replace="all" but then you need to find a way to update the
   instance data in the new page.

o Use replace="instance", but make sure you return an XML document
   which contains the instance data to replace.

 > I know that If I use a get method I will lost the XML structure, but
 > this is not very important for me.

Check the flickr-search JSP example that ships with Orbeon Forms (I
attach it as well): in just a few lines, it reads a posted XML
document and extracts values from it. It's really easy ;-)

-Erik

--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/


<%--
    Copyright (C) 2006 Orbeon, Inc.

    This program is free software; you can redistribute it and/or modify it under the terms of the
    GNU Lesser General Public License as published by the Free Software Foundation; either version
    2.1 of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the GNU Lesser General Public License for more details.

    The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
--%>
<%@ page import="java.net.URL"%>
<%@ page import="org.dom4j.io.SAXReader"%>
<%@ page import="org.dom4j.Document"%>
<%@ page import="org.dom4j.Element"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.net.URLEncoder"%>
<%
    response.setContentType("application/xml");
    SAXReader xmlReader = new SAXReader();

    // Build URL for query to Flickr
    String flickrURL = "http://www.flickr.com/services/rest/?method=";
    if ("POST".equals(request.getMethod())) {
        // We go a query string
        Document queryDocument = xmlReader.read(request.getInputStream());
        String query = queryDocument.getRootElement().getStringValue();
        flickrURL = "http://www.flickr.com/services/rest/?method=flickr.photos.search&text=" + URLEncoder.encode(query, "UTF-8");
    } else {
        // No query, return interesting photos
        flickrURL += "flickr.interestingness.getList";
    }
    flickrURL += "&per_page=200&api_key=d0c3b54d6fbc1ed217ecc67feb42568b";

    Document flickrResponse = xmlReader.read(new URL(flickrURL));
    Element photosElement = flickrResponse.getRootElement().element("photos");
%>
<photos>
<%  for (Iterator photoIterator = photosElement.elementIterator(); photoIterator.hasNext();) {
        Element photo = (Element) photoIterator.next();
        String photoURL = "http://static.flickr.com/" + photo.attributeValue("server") + "/" + photo.attributeValue("id")
            + "_" + photo.attributeValue("secret") + "_s.jpg";
        String pageURL = "http://flickr.com/photos/" + photo.attributeValue("owner") +"/" + photo.attributeValue("id") + "/";
%>
    <photo url="<%=photoURL%>" page="<%=pageURL%>"/>
<%  } %>
</photos>


--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: submitting xforms throw struts

Jose Gato Lui
Thank you Erik, but I still have a doubt:

If I use a post method, how could I access to the form information from
the jsp action?

Now, I only can access to the form information If I use submit get
method.



El lun, 29-01-2007 a las 11:42 +0100, Erik Bruchez escribió:

> Jose,
>
>  > Hello all, in my company we are trying to use XForms in our platform
>  > based in struts/jsp.
>  >
>  > In this moment I have an XForm form that I want to submit to our
>  > application in this way:
>  >
>  >  <xforms:submission id="submitIntercambioTareas"
>  > ref="instance('mainForm')" method="get" replace="instance"
>  > instance="mainForms"
>  > action="http://localhost:9000/opencities/testXForms.do"
>  > separator="&amp;" />
>  >
>  > The testXForms.do struts call to an action java class:
>  >
>  > <action path="/testXForms"
>  >
> type="com.andago.opencities.struts.actions.mantenimiento.testXFormsAction"
>  > name="testXFormsForm"
>  > scope="session"
>  > validate="false">
>  > <forward name="success" path="/web/jsp/comun/testXForms.jsp" />
>  > </action>
>  >
>  >
>  > in this class(testXformsAction) I can access to the complete instance
>  > "mainForm" because I have a java form bean(testXFormsForm) with the same
>  > parameters like the XForm:
>  >
>  > form.getFoo();
>  > form.getBar();
>  >
>  > Now the problems:
>  >
>  > - This only works with get method, because the xforms travels in the
>  > url: http://localhost:9000/opencities/testXForms.do?foo=13&bar=123... If
>  > I use a post method I cannot acces to the form with:
>  >   form.getFoo();
>
>  > - Using get method If I modified the values of the form in the action
>  > class:
>  >
>  >     form.setFoo = 567
>  >
>  >   This new values are not refreshed in my XForm instance when the struts
>  > fordward call again my XForm web page.
>
> Right, this will not occur automatically!
>
> First, there is a problem with your submission: it says
> replace="instance", which means that your submission must return an
> XML document. You don't do this, what you do is that you forward the
> result of the JSP page that produces the whole XForms page again.
>
> So either:
>
> o Use replace="all" but then you need to find a way to update the
>    instance data in the new page.
>
> o Use replace="instance", but make sure you return an XML document
>    which contains the instance data to replace.
>
>  > I know that If I use a get method I will lost the XML structure, but
>  > this is not very important for me.
>
> Check the flickr-search JSP example that ships with Orbeon Forms (I
> attach it as well): in just a few lines, it reads a posted XML
> document and extracts values from it. It's really easy ;-)
>
> -Erik
>
> documento de texto sencillo adjunto (service-search.jsp)
> <%--
>     Copyright (C) 2006 Orbeon, Inc.
>
>     This program is free software; you can redistribute it and/or modify it under the terms of the
>     GNU Lesser General Public License as published by the Free Software Foundation; either version
>     2.1 of the License, or (at your option) any later version.
>
>     This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
>     without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>     See the GNU Lesser General Public License for more details.
>
>     The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
> --%>
> <%@ page import="java.net.URL"%>
> <%@ page import="org.dom4j.io.SAXReader"%>
> <%@ page import="org.dom4j.Document"%>
> <%@ page import="org.dom4j.Element"%>
> <%@ page import="java.util.Iterator"%>
> <%@ page import="java.net.URLEncoder"%>
> <%
>     response.setContentType("application/xml");
>     SAXReader xmlReader = new SAXReader();
>
>     // Build URL for query to Flickr
>     String flickrURL = "http://www.flickr.com/services/rest/?method=";
>     if ("POST".equals(request.getMethod())) {
>         // We go a query string
>         Document queryDocument = xmlReader.read(request.getInputStream());
>         String query = queryDocument.getRootElement().getStringValue();
>         flickrURL = "http://www.flickr.com/services/rest/?method=flickr.photos.search&text=" + URLEncoder.encode(query, "UTF-8");
>     } else {
>         // No query, return interesting photos
>         flickrURL += "flickr.interestingness.getList";
>     }
>     flickrURL += "&per_page=200&api_key=d0c3b54d6fbc1ed217ecc67feb42568b";
>
>     Document flickrResponse = xmlReader.read(new URL(flickrURL));
>     Element photosElement = flickrResponse.getRootElement().element("photos");
> %>
> <photos>
> <%  for (Iterator photoIterator = photosElement.elementIterator(); photoIterator.hasNext();) {
>         Element photo = (Element) photoIterator.next();
>         String photoURL = "http://static.flickr.com/" + photo.attributeValue("server") + "/" + photo.attributeValue("id")
>             + "_" + photo.attributeValue("secret") + "_s.jpg";
>         String pageURL = "http://flickr.com/photos/" + photo.attributeValue("owner") +"/" + photo.attributeValue("id") + "/";
> %>
>     <photo url="<%=photoURL%>" page="<%=pageURL%>"/>
> <%  } %>
> </photos>
> documento de texto sencillo adjunto (message-footer.txt)
> --
> 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
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
--
José Gato Luis
Departamento de I+D
Ándago Ingeniería - www.andago.com

Teléfono: +34 916 011 373
e-mail: [hidden email]




--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: submitting xforms throw struts

Erik Bruchez
Administrator
Jose,

By JSP action, do you mean Struts action? The JSP file I attached to my
previous email shows exactly that. You can use the same code in a Struts
action: you just need to have access to the HttpServletRequest object.

-Erik

Erik Bruchez wrote:
 > Jose,
 >
 >  > Hello all, in my company we are trying to use XForms in our platform
 >  > based in struts/jsp.
 >  >
 >  > In this moment I have an XForm form that I want to submit to our
 >  > application in this way:
 >  >
 >  >  <xforms:submission id="submitIntercambioTareas"
 >  > ref="instance('mainForm')" method="get" replace="instance"
 >  > instance="mainForms"
 >  > action="http://localhost:9000/opencities/testXForms.do"
 >  > separator="&amp;" />
 >  >
 >  > The testXForms.do struts call to an action java class:
 >  >
 >  > <action path="/testXForms"
 >  >
 >
type="com.andago.opencities.struts.actions.mantenimiento.testXFormsAction"
 >  > name="testXFormsForm"
 >  > scope="session"
 >  > validate="false">
 >  > <forward name="success" path="/web/jsp/comun/testXForms.jsp" />
 >  > </action>
 >  >
 >  >
 >  > in this class(testXformsAction) I can access to the complete instance
 >  > "mainForm" because I have a java form bean(testXFormsForm) with
the same
 >  > parameters like the XForm:
 >  >
 >  > form.getFoo();
 >  > form.getBar();
 >  >
 >  > Now the problems:
 >  >
 >  > - This only works with get method, because the xforms travels in the
 >  > url:
http://localhost:9000/opencities/testXForms.do?foo=13&bar=123... If
 >  > I use a post method I cannot acces to the form with:
 >  >   form.getFoo();
 >
 >  > - Using get method If I modified the values of the form in the action
 >  > class:
 >  >
 >  >     form.setFoo = 567
 >  >
 >  >   This new values are not refreshed in my XForm instance when the
struts
 >  > fordward call again my XForm web page.
 >
 > Right, this will not occur automatically!
 >
 > First, there is a problem with your submission: it says
 > replace="instance", which means that your submission must return an
 > XML document. You don't do this, what you do is that you forward the
 > result of the JSP page that produces the whole XForms page again.
 >
 > So either:
 >
 > o Use replace="all" but then you need to find a way to update the
 >   instance data in the new page.
 >
 > o Use replace="instance", but make sure you return an XML document
 >   which contains the instance data to replace.
 >
 >  > I know that If I use a get method I will lost the XML structure, but
 >  > this is not very important for me.
 >
 > Check the flickr-search JSP example that ships with Orbeon Forms (I
 > attach it as well): in just a few lines, it reads a posted XML
 > document and extracts values from it. It's really easy ;-)
 >
 > -Erik
 >


--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: submitting xforms throw struts

Jose Gato Lui
Thanks Erik, you are right Its very easy to have the xform information
from a JSP using an HttpServletRequest object.

I suposse that I have to fill a HttpServletResponse object to return a
new xml to the xform web page, but Im having many problems, Im doing
something like that:

ServletOutputStream out = response.getOutputStream();
response.setContentType("text/xml");
out.println("<numeroExpediente>666</numeroExpediente>");
out.flush();
out.close();

ahhm Im using Structs actions, with this code I have an exception:


ERROR
org.apache.catalina.core.ContainerBase.[jonas].[localhost].[/opencities].[hero] : Servlet.service() for servlet hero threw exception
java.lang.IllegalStateException: Cannot forward after response has been
committed
        at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:313)
        at org.apache.catalina.core.ApplicationDispatcher.access
$000(ApplicationDispatcher.java:66)
        at org.apache.catalina.core.ApplicationDispatcher
$PrivilegedForward.run(ApplicationDispatcher.java:81)
        at java.security.AccessController.doPrivileged(Native Method)
        at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:293)
        at
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
        at
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
        at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
        at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
        at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
        at sun.reflect.GeneratedMethodAccessor191.invoke(Unknown Source)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.catalina.security.SecurityUtil
$1.run(SecurityUtil.java:243)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
        at
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:275)
        at
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:161)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:245)
        at org.apache.catalina.core.ApplicationFilterChain.access
$000(ApplicationFilterChain.java:50)
        at org.apache.catalina.core.ApplicationFilterChain
$1.run(ApplicationFilterChain.java:156)
        at java.security.AccessController.doPrivileged(Native Method)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:152)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at
org.objectweb.jonas.web.catalina55.ResetAuthenticationValve.invoke(ResetAuthenticationValve.java:62)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at org.apache.coyote.http11.Http11BaseProtocol
$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667)
        at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)
Error
  java.io.IOException: Stream closed


thank you again Erik...

El mar, 06-02-2007 a las 21:07 +0100, Erik Bruchez escribió:

> Jose,
>
> By JSP action, do you mean Struts action? The JSP file I attached to my
> previous email shows exactly that. You can use the same code in a Struts
> action: you just need to have access to the HttpServletRequest object.
>
> -Erik
>
> Erik Bruchez wrote:
>  > Jose,
>  >
>  >  > Hello all, in my company we are trying to use XForms in our platform
>  >  > based in struts/jsp.
>  >  >
>  >  > In this moment I have an XForm form that I want to submit to our
>  >  > application in this way:
>  >  >
>  >  >  <xforms:submission id="submitIntercambioTareas"
>  >  > ref="instance('mainForm')" method="get" replace="instance"
>  >  > instance="mainForms"
>  >  > action="http://localhost:9000/opencities/testXForms.do"
>  >  > separator="&amp;" />
>  >  >
>  >  > The testXForms.do struts call to an action java class:
>  >  >
>  >  > <action path="/testXForms"
>  >  >
>  >
> type="com.andago.opencities.struts.actions.mantenimiento.testXFormsAction"
>  >  > name="testXFormsForm"
>  >  > scope="session"
>  >  > validate="false">
>  >  > <forward name="success" path="/web/jsp/comun/testXForms.jsp" />
>  >  > </action>
>  >  >
>  >  >
>  >  > in this class(testXformsAction) I can access to the complete instance
>  >  > "mainForm" because I have a java form bean(testXFormsForm) with
> the same
>  >  > parameters like the XForm:
>  >  >
>  >  > form.getFoo();
>  >  > form.getBar();
>  >  >
>  >  > Now the problems:
>  >  >
>  >  > - This only works with get method, because the xforms travels in the
>  >  > url:
> http://localhost:9000/opencities/testXForms.do?foo=13&bar=123... If
>  >  > I use a post method I cannot acces to the form with:
>  >  >   form.getFoo();
>  >
>  >  > - Using get method If I modified the values of the form in the action
>  >  > class:
>  >  >
>  >  >     form.setFoo = 567
>  >  >
>  >  >   This new values are not refreshed in my XForm instance when the
> struts
>  >  > fordward call again my XForm web page.
>  >
>  > Right, this will not occur automatically!
>  >
>  > First, there is a problem with your submission: it says
>  > replace="instance", which means that your submission must return an
>  > XML document. You don't do this, what you do is that you forward the
>  > result of the JSP page that produces the whole XForms page again.
>  >
>  > So either:
>  >
>  > o Use replace="all" but then you need to find a way to update the
>  >   instance data in the new page.
>  >
>  > o Use replace="instance", but make sure you return an XML document
>  >   which contains the instance data to replace.
>  >
>  >  > I know that If I use a get method I will lost the XML structure, but
>  >  > this is not very important for me.
>  >
>  > Check the flickr-search JSP example that ships with Orbeon Forms (I
>  > attach it as well): in just a few lines, it reads a posted XML
>  > document and extracts values from it. It's really easy ;-)
>  >
>  > -Erik
>  >
>
>
> documento de texto sencillo adjunto (message-footer.txt)
> --
> 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
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
--
José Gato Luis
Departamento de I+D
Ándago Ingeniería - www.andago.com

Teléfono: +34 916 011 373
e-mail: [hidden email]




--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws