The best place to do a one-time initialization of the data model is the
getFormModel() method.
This is the orginial in the AbstractXMLFormAction:

  /**
   * Extract xmlform-model
   * action parameter and
   * instantiate a new form model it.
   *
   *
   * Subclasses may override this method
   * to use custom model instantiation technique
   *
   */
  protected Object getFormModel()
  {
    try
      {
        String modelClassName =
getParameters().getParameter("xmlform-model", null);
        Class modelClass = Class.forName ( modelClassName );
        Object o = modelClass.newInstance ();
        return o;
      }
      catch ( Exception e)
      {
        throw new CascadingRuntimeException( " Failed instantiating form
model ", e );
      }
  }


You can override this method and do the following:

  protected Object getFormModel()
  {
    // create a dom document and initialize it
    // preferably use the JXPath DocumentContainer
  }


This way, the first XMLForm page will use the initialized version.


Let me know if this works for you.



Ivelin



----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, December 09, 2002 10:13 AM
Subject: RE: XMLForm: content listbox problem


Hi Lars,

You said that I should initialize the bean in the prepare method.
What do you do exactly?

For my Bean I started from the Wizard example code. The initialization is in
the perform method.

regards
Thank you
Sylvain



-----Message d'origine-----
De: Kirchhoff, Lars [mailto:[EMAIL PROTECTED]]
Date: lundi, 9. décembre 2002 09:38
Ŕ: '[EMAIL PROTECTED]'
Objet: AW: XMLForm: content listbox problem


I'm sorry confusing you with this. This are just integer values
which returns me how the function was executed.

That means getTransactionData returns an integer value with the
number of elements. So that I can decide on this what should be
done next. (I'm new to cocoon and java as well and am not sure
if this is a correct or good way to do, but it works for me now,
if anybody has a clearer or better aproach I would be very pleased
to know about it)

public int getTransactionData() {
...
return numberOfTransactions;
}

so try to initialize the bean in the prepare method as well and see
whats happening.

ciao Lars


> -----Ursprüngliche Nachricht-----
> Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Gesendet: Montag, 9. Dezember 2002 16:28
> An: [EMAIL PROTECTED]
> Betreff: RE: XMLForm: content listbox problem
>
>
> Hello Lars,
>
> I call the getModel() method in the perform function, like
> the Wizard example:
>
> ----code
> public Map perform() {
>   AddWorkstationBean jBean = (AddWorkstationBean)
> getForm().getModel();
>   if (getCommand().equals(CMD_NEXT)&&
> getForm().getViolations() != null) {
> return page(getFormView());
>   } else {
>     getForm().clearViolations();
>     String command = getCommand();
>     String formView = getFormView();
>
>     if (formView.equals(VIEW_FORM1)) {
>       if (command.equals(CMD_NEXT)) {
>   return page(VIEW_FORM2);
> }
> } else if (formView.equals(VIEW_FORM
> ..
> etc....
> ..
> ----code
>
> I don't understand what mean the result_trans and result_cust
> properties. Are they Bean properties?
>
> Thank you
> Regards
> Sylvain
>
>
>
>
>
> -----Message d'origine-----
> De: Kirchhoff, Lars [mailto:[EMAIL PROTECTED]]
> Date: lundi, 9. décembre 2002 03:32
> Ŕ: '[EMAIL PROTECTED]'
> Objet: AW: XMLForm: content listbox problem
>
>
> Hello Sylvian,
>
> I always initialize the data for the appropriate form. This means
> I put the initialize data actions in different functions and call
> them if I reach the stage.  Here is an example:
>
> ----- code
> if ( formView.equals ( VIEW_START ) ) {
>       if ( command.equals( CMD_COMMIT ) ) {
>       int result_trans =
> jBean.getTransactionData();
>       int result_cust = jBean.getUserData();
>
>       if ( result_cust == 0 ) {
>       return page( VIEW_ERROR );
>       }
>       else if ( result_trans == 0 ) {
>       return page( VIEW_ERROR );
>           }
>
>      else if ( result_cust > 1 ) {
>      return page( VIEW_CUSTOMER );
>      }
>      else {
>      return page( VIEW_INVOICE );
>      }
> }
> }
> ----- /code
>
> this allows me also to react on different results from these
> functions.
> When did you call the getModel() method from the bean?  Are you doing
> that in the prepare or perform function?
>
> ciao Lars
>
> > -----Ursprüngliche Nachricht-----
> > Von: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]
> > Gesendet: Freitag, 6. Dezember 2002 00:01
> > An: [EMAIL PROTECTED]
> > Betreff: XMLForm: content listbox problem
> >
> >
> > Hello,
> >
> > I have an XMLForm app like this:
> >
> > Navigation:
> > Start->Form1->Form2->Confirm->End
> >
> > In the Form1 view I have a listbox. The content (the
> > different choices) of this listbox comes from an XML file.
> > The code is:
> > <xf:selectOne ref="/workstationType">
> >   <xf:caption>Workstation Type</xf:caption>
> >   <xf:itemset nodeset="select/document/typeOfWorkstation/item">
> >     <xf:caption ref="description"/>
> >     <xf:value ref="@id"/>
> >   </xf:itemset>
> >   <xf:violations class="error"/>
> > </xf:selectOne>
> >
> > This code seems to be OK. The XPath code is also OK I think.
> > Here is the XML file:
> > <document>
> >   <typeOfWorkstation>
> >     <item id="desktop">
> >       <description>Desktop</description>
> >     </item>
> >     <item id="laptop">
> >       <description>Laptop</description>
> >     </item>
> >     <item id="other">
> >       <description>Other configuration</description>
> >     </item>
> >   </typeOfWorkstation>
> > </document>
> >
> >
> > I load the XML file in a DOM Node property (called "select").
> > This property is located in the Bean file (with getter and
> > setter methods for this property). I load the XML file in
> > this Node property also in the Bean file, in the constructor.
> > Here the Bean file:
> >
> > public class AddWorkstationBean {
> > private String workstationName;
> > private String workstationType;
> > private String workstationOwner;
> > private String workstationUser;
> >
> > private Node select; //values from the XML file
> >
> > public AddWorkstationBean() {
> > initSelect();
> > }
> >
> > public Node initSelect() {
> > //initialize a property named "select" of DOM Node class
> > DOMImplementation impl;
> > try {
> > // Find the implementation
> > DocumentBuilderFactory factory =
> > DocumentBuilderFactory.newInstance();
> > factory.setNamespaceAware(false);
> > factory.setValidating(false);
> > DocumentBuilder builder =
> > factory.newDocumentBuilder();
> > impl = builder.getDOMImplementation();
> >
> > //Create the node for the root "select"
> > Document document =
> > impl.createDocument(null, "select", null);
> > Node selectName = document.getDocumentElement();
> >
> > //Loading from XML File
> > String fileName =
> >
> > "C:\\jakarta-tomcat-4.1.12\\webapps\\cocoon\\woc\\iniForm.xml";
> > FileInputStream inXML = new
> > FileInputStream(fileName);
> > BufferedReader in =
> > new BufferedReader(new
> > InputStreamReader(inXML));
> > Element element = XMLLoader.loadFromStream(in);
> >
> > //Import the node
> > Element importedElement =
> > (Element)
> > document.importNode(element, true);
> > selectName.appendChild(importedElement);
> >
> > //initialize the porperty
> >
> > select = selectName;
> > }
> >
> > .. getter an setter methods..
> > ..
> >
> > }
> >
> >
> > My problem is when I start the app (with the Start view) and
> > then display the Form1 there is NOTHING in the listbox (the
> > list isn't empty but it's like the caption and value
> > properties are null)!!
> > Then I go to the next view (Form2). Then if I press the
> > Preview button and go back to the Form1, the listbox is OK!!
> > It's crazy and I really don't understand why!
> >
> > Someone could help me?
> > Any suggestions will be greatly appreciated!
> >
> > Thank you
> > Sylvain
> >
> >
> ---------------------------------------------------------------------
> > Please check that your question  has not already been
> answered in the
> > FAQ before posting.
> <http://xml.apache.org/cocoon/faq/index.html>
> >
> > To unsubscribe, e-mail:
> <[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> <[EMAIL PROTECTED]>
> >
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
> For additional commands, e-mail:   <[EMAIL PROTECTED]>
>
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
> For additional commands, e-mail:   <[EMAIL PROTECTED]>
>

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to