What I've done is create an action that extends AbstractXMLFormAction and
overrides the getFormModel method. The following piece of code uses object
persistance to get the model from the database.

protected Object getFormModel(){
    //If there is an non-zero id request parameter i.e. form?id=11 get model
from database
    if (recordId>0){
      PersistenceBroker
broker=(PersistenceBroker)servletContext.getAttribute("persistenceBroker");
      Object model=null;
      try {
        Criteria criteria=new Criteria();
        criteria.addEqualTo("id",new Integer(recordId));
        model=broker.getObjectByQuery(new
QueryByCriteria(Class.forName(getParameter("xmlform-model")),criteria));
      } catch (Exception e){
        getLogger().error("Problem getting record: "+e.getMessage());
      }
      return model;
    } else
        //Other-wise create a blank model
      return super.getFormModel();
  }

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: 14 January 2003 16:18
To: [EMAIL PROTECTED]
Subject: [XMLForm] how to dynamically initialize a bean property?


Hello,

In my XMLForm application I want to initialize a bean property each time I
load the application because the initialization value changes all the time
(to find the initialization value I retrieve a value, which is also dynamic,
from a database and I increment it).

If I initialize the property in the bean constructor, I have seen that the
property is initialized only the first time I load the application.

How to do that if I want to initialize the property each time?

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]>

Reply via email to