cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rashel Shehata" <rashe...@gmail.com>
Subject Re: dynamic cForm generation
Date Mon, 23 Apr 2007 04:42:23 GMT
Hi,
after looking at the patch provided at:
https://issues.apache.org/jira/browse/COCOON-1418

I thought it was a bit drastic to change cocoon source code, and also will
cause portability issues...
so to fix my issue, i place the data structures that my jx generator uses in
a session variables, that way when i call form constructor, i dont ned to
pass it an object...
this is what i have so far:
in my flowscript:

function do_finalPreview(){

 cocoon.session.setAttribute("questions",questionRegistry.getAllQuestions()
);
 cocoon.session.setAttribute("style",questionRegistry.getStyle() );
   var form = new Form("cocoon:/form_model-pipeline.xsp");

  form.showForm("finalPreview-display-pipeline");

 }
in the sitemap, the relevant entries are:

     <map:match pattern="*-pipeline.xsp">
       <map:generate type="jx" src="forms/{1}.xml"/>
       <map:serialize type="xml"/>
     </map:match>
which generates the serialized xml for form definition and

     <map:match pattern="finalPreview-display-pipeline">
       <map:generate src="cocoon:/form_templateToXml-pipeline.xsp"/>
       <map:transform type="forms" label="content1"/>
       <map:transform type="i18n">
       </map:transform>
       <map:call resource="simple-page2html">
         <map:parameter name="file" value="cocoon:/form_templateToXml-
pipeline.xsp"/>
       </map:call>
       <map:transform src="resources/forms-samples-styling.xsl">
         <map:parameter name="resources-uri"
value="{request:contextPath}/_cocoon/resources"/>
       </map:transform>
       <map:transform type="i18n">
       </map:transform>
       <map:serialize/>
     </map:match>
the src used for the generator
(src="cocoon:/form_templateToXml-pipeline.xsp") refers
to another pipeline entry which genrates the seialized xml for
form template,

I'm having a problem with this form generation.... when the form is
displayed, the section groups are displayed probably (fieldset|div or tab
style, and group labels etc) however the widgets within the groups are not
been displayed at all...
I tested the generated form def and template statistically and found that
the same problem occurs. After reviewing, I found that by adding the tag:
  <jx:import uri="resource://org/apache/cocoon/forms/generation/jx-
macros.xml"/>
to the form template will cause the form to display probably.
Adding this tag however to my jx generator for teh form template gives me
this error:

org.apache.cocoon.forms.FormsRuntimeException: The template cannot find a
form object
*<jx:set>* - resource://org/apache/cocoon/forms/generation/jx-macros.xml -
49:117


a snippet of my jx generatot for the form template is:

<?xml version="1.0"?>
<page xmlns:ft="http://apache.org/cocoon/forms/1.0#template"
      xmlns:fi="http://apache.org/cocoon/forms/1.0#instance"
      xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
   >
  <jx:import uri="resource://org/apache/cocoon/forms/generation/jx-
macros.xml"/>

  <content>
   <ft:form-template action="continue" method="POST">
   <jx:forEach var="section" items="${cocoon.session.getAttribute
('style')}">
<jx:choose>
...

Can anyone explain this problem to me? I dont really get what's happening



Thanks a million



On 4/19/07, Rashel Shehata <rashel.s@gmail.com> wrote:
>
> Hi,
> Thank you all for all the help...
> I am trying the suggestion found in  https://issues.apache.org/jira/browse/COCOON-1418
>
> so many thanks for the hint
>
> Regards
>
>
>  On 4/18/07, Jason Johnston <cocoon@lojjic.net> wrote:
> >
> > Philippe Gauthier - INSERM SIRH wrote:
> > >   Hi Rashel,
> > >
> > > U shouldn't use a dynamic form definition, because it means for each
> > > call, cocoon will have to compile a new form and can't use any
> > caching.
> > > I did the same mistake using xslt transformation to generate the
> > > definition (using pipelineToStream to save it to disk temporary) and
> > it
> > > killed the JVM eventually .
> > > And that's why the form instantiation function takes only system file.
> > >
> > > Instead u have to understand the binding concepts of forms an redesign
> > a
> > > or some generic forms definition and templates with more complex
> > widgets.
> > > Then u'll be have able to fill thoses forms with dynamic data.
> > > I hope I gave U the right pointers, sorry for my english.
> >
> > I agree that it's preferable to have a static form definition with
> > dynamic widgets that modify the structure of the form at runtime.  But
> > there are cases where that's not possible, so true dynamic form creation
> > is a useful tool to have.
> >
> > What you say about caching the form definition is also true but is only
> > an issue if the pipeline that generates it is not cacheable.  If all of
> > that pipeline's components are cacheable then the form definition is
> > cached IIUC.
> >
> > Rashel, what you are looking for I believe is this:
> >
> >   var form = new Form("cocoon:/my-dynamic-form-def-pipeline");
> >
> > That uses the result of a Cocoon pipeline to build the form definition.
> > Unfortunately, currently the Form constructor does not allow passing
> > flow attributes as a second argument; there is an open issue in Jira for
> > adding that feature: https://issues.apache.org/jira/browse/COCOON-1418
> >
> > In the absence of that feature you can pass along the data in another
> > way, for instance setting it as an attribute on the request.  Or you
> > could try applying the patch attached to that Jira issue.
> >
> > Finally, if you're using JX to generate the definition XML, I'd strongly
> >
> > suggest using jx:cache-key and jx:cache-validity to control the caching
> > of the result if possible, that way you'll avoid the performance/memory
> > issue Philippe warned of.  This feature might only be available in the
> > 'newjx' version of JXTemplateGenerator; details at
> > http://wiki.apache.org/cocoon/JXTemplateGenerator
> >
> > --Jason
> >
> > >
> > > regards,
> > >
> > > Philippe
> > >
> > > Rashel Shehata a écrit :
> > >> Hi Bart,
> > >> Ok so  to create the form definition xml the jx generator uses the
> > >> following xml file:
> > >> I pass it an array object ( questionRegistry.getAllQuestions()) that
> > >> contains a list of all the questions to be created in the form
> > >>
> > >> <?xml version="1.0"?>
> > >> <fd:form xmlns:fd=" http://apache.org/cocoon/forms/1.0#definition"
> > >>          xmlns:i18n=" http://apache.org/cocoon/i18n/2.1"
> > >>     xmlns:jx=" http://apache.org/cocoon/templates/jx/1.0">
> > >>
> > >>
> > >> <fd:widgets>
> > >>
> > >>    <jx:forEach var="question" items="${questions}">
> > >>
> > >>    <jx:choose>
> > >>  <jx:when test="${question.responseType == 'multivalue-field'}">
> > >>   <fd:multivaluefield id='${question.ID}'
> > >> required='${ question.required}' state='${question.state}'>
> > >>     <fd:label>     ${question.label} </fd:label>
> > >>     <fd:help>${ question.help}</fd:help>
> > >>        <fd:hint>${ question.hint}</fd:hint>
> > >>      <fd:datatype base="long"></fd:datatype>
> > >>      <fd:selection-list>
> > >>      <jx:forEach var="response" items="${ question.responses}">
> > >>      <fd:item value='${response.ID}'>
> > >>         <fd:label>${response.label}</fd:label>
> > >>         </fd:item>
> > >>
> > >>    </jx:forEach>
> > >>    </fd:selection-list>
> > >>   </fd:multivaluefield>
> > >>
> > >>   </jx:when>
> > >>
> > >>   <jx:when test="${question.responseType == 'checkbox'}">
> > >>   <fd:booleanfield id='${question.ID}' required='${
> > >> question.required}' state='${question.state}'>
> > >>     <fd:label>     ${question.label} </fd:label>
> > >>     <fd:help>${question.help}</fd:help>
> > >>        <fd:hint>${question.hint }</fd:hint>
> > >>    </fd:booleanfield>
> > >>
> > >>   </jx:when>
> > >>
> > >>  <jx:otherwise>
> > >>    <fd:field id='${question.ID}' required='${question.required}'
> > >> state='${question.state}'>
> > >>        <fd:label>     ${ question.label} ${question.responseType
}
> > >> </fd:label>
> > >>     <fd:help>${question.help}</fd:help>
> > >>        <fd:hint>${question.hint}</fd:hint>
> > >>
> > >> ...
> > >>
> > >>   </fd:field>
> > >>  </jx:otherwise>
> > >>    </jx:choose>
> > >>    </jx:forEach>
> > >>  </fd:widgets>
> > >>  </fd:form>
> > >>
> > >>
> > >>
> > >>
> > >> the jx generator then outputs the serialized xml to the browser,
> > where
> > >> the xml is in correct cForm syntax... it's similar for the
> > >> form template also...
> > >>
> > >> I now want to do use both serialized xml and feed it back into a
> > >> pipeline entry so i can view the generated form as a HTML form...
> > >>
> > >>
> > >>
> > >> I hope this made my problem clearer..
> > >>
> > >>
> > >>
> > >> Thanks heaps
> > >>
> > >> On 4/18/07, *bart remmerie* <remmerie@gmail.com
> > >> <mailto: remmerie@gmail.com>> wrote:
> > >>
> > >>     Dear Rashel,
> > >>
> > >>     Could you give an example/snippet of one of these .xml files ?
> > >>
> > >>     Bart
> > >>
> > >>     2007/4/18, Rashel Shehata < rashel.s@gmail.com
> > >>     <mailto:rashel.s@gmail.com>>:
> > >>
> > >>         Hey,
> > >>
> > >>         I'm trying to generate cocoon forms dynamically. atm I create
> >
> > >>         the cForm model xml dynamically using jx generator; this is
> > >>         what i have:
> > >>
> > >>         in my flowscript:
> > >>           cocoon.sendPage("form_model-pipeline.xsp " ,
> > >>              {questions: questionRegistry.getAllQuestions()});
> > >>
> > >>         and in my pipeline:
> > >>         <map:match pattern="*-pipeline.xsp">
> > >>                <map:generate type="jx" src="forms/{1}.xml"/>
> > >>                <map:serialize type="xml"/>
> > >>              </map:match>
> > >>
> > >>         the jx generator creates a cForm xml model in correct syntax
> > >>         and is outputted as XML to the browser...
> > >>
> > >>         what im trying to do now is feed this newly generated xml
> > >>         model to the pipeline so that a Form will be generated and
> > >>         viewed, however i'm not really sure how to do this, or which
> > >>         part of cocoon docos i sould be reading...
> > >>         How do I dynamically generate input content to be used as a
> > >>         source in the sitemap??
> > >>
> > >>
> > >>         Any help would be appreciated...
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>     --
> > >>     Bart Remmerie
> > >>
> > >>
> > >
> > >
> > > --
> > > Philippe Gauthier
> > > INSERM
> > > DRH - SIRH
> > > Tel: 01.44.23.62.57
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail: users-help@cocoon.apache.org
> >
> >
>

Mime
View raw message