You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Bertrand Delacretaz <bd...@codeconsult.ch> on 2002/11/21 10:04:13 UTC

[RT] BEans And Forms Framework (BEAFF)

--- INTRO ---
I think Torsten Curdt's GetTogether presentation [1] of the various ways of 
writing webapps with Cocoon makes it clear that something better is needed to 
write CRUD [2] applications with Cocoon.

No-one wants to have to modify three configuration files in three different 
languages every time a field is added to or removed from a form.

Here's my suggestion for a simple framework for data entry and forms-to-beans 
mapping. I think using this together with flowscript, Hibernate [3] or OJB 
[4] for storage and XSLT for presentation would be all that is needed to 
build CRUD webapps fairly easily and in a very scalable way.

--- ASSUMPTIONS ---
These describe how I'd like to build webapps. BEAFF (or elements of it) would 
certainly be usable in other contexts but initial development should focus on 
a simple environment.

-Cocoon is used to build CRUD [2] applications. 

-Business logic is implemented in backend java classes.

-Java Beans (not EJB - normal java classes with Beans name conventions) are 
used to hold data and interface with the backend.

-Flowscript is used for flow control and interface between frontend (forms) 
and backend (beans). 

-Except for very simple stuff (required fields etc.), data validation is done 
by the java backend. I don't want junior programmers working on flow changes 
or page layout to risk breaking the business level validations, and backend 
code and validations usually outlives the front-end and flow stuff, so it 
makes sense for me to keep them together.

--- BEAFF - THE PLAN ---
-Use an XML-based data dictionary (DD) for fields, datatypes and beans 
definitions. See example below.

-DD can use enumerated types obtained in XML from Cocoon pipelines.

-A Transformer creates form fields by replacing placeholder elements in pages 
by appropriate labels (i18n-able) and data entry elements (HTML <input> and 
the like) computed from the DD. Custom "field builders" can optionally be 
used.

-A Transformer populates forms values by using DD definitions to get data 
from Beans. Custom mapping classes can optionally be used.

-BEAFF classes are used (by the flowscript layer) to convert suitable HTTP 
request parameters into the appropriate java data types based on DD mappings. 
This includes basic validity checks (string-to-integer etc.). Custom mapping 
classes can optionally be used.

-BEAFF classes are used by the flowscript layer to move this converted data 
into the beans, form-by-form, without having to explicitely write copying 
code for each field. This uses java reflection mechanisms to be fully dynamic.

-Beans classes are generated at compile-time by an ant task based on DD 
information. Generated Beans include hook functions to allow data validation 
and database interactions to happen in derived classes written by the 
application programmer.

--- EXAMPLE DD ---
I don't know XForms and schema stuff very well, maybe these could be used 
instead of a custom DD format. The aim here is to describe what must be in 
the DD, not necessarily to be an implementation format.

<data-dictionary name="cd-library" java-package="myapp.beans">
  <!-- custom data types -->
  <data-types>
    <data-type
      name="musical-style"
      class="beaff.enumeration" 
      src="cocoon:/enums/styles.xml"
      string-converter="myapp.formats.StyleFormatterAndParser"
    >
    </data-type>
  </data-types>

  <!-- reusable field definitions -->
  <field-types>
    <field-type name="artist" data-type="myapps.beans.Artist"/>
  </field-types>

  <!-- application data model -->
  <beans>
    <bean name="MusicCd">
      <field data-type="java.lang.String" name="title" required="true"/>
      <field data-type="musical-style" name="style"/>
      <field data-type="artist" name="artist" required="true"/>
    </bean>

    <bean name="Artist">
      <field data-type="java.lang.String" name="name" required="true"/>
    </bean>
  </beans>

</data-dictionary>

I think this is sufficient to generate fields in forms, map beans values to 
forms and map HTTP request parameters to beans. 

Of course more DD options will be needed for custom formatters/parsers but 
for a start the above should be sufficient.

--- CODA ---
I cannot imagine this doesn't exist yet, but I couldn't find a library that 
does all that we need here. Suggestions?

The power of BEAFF lies in the leverage given by the DD - changing DD info 
updates all the required pieces of the application front-end (and backend 
interface) with minimal effort.

Other than that: fire away... ;-)

-- 
 Bertrand Delacrétaz (codeconsult.ch, jfor.org)
 blogspace http://www.codeconsult.ch/bertrand

[1] 
http://outerthought.net/gettogether/12%20-%20presentation%20-%20torsten.pdf
[2] CRUD=Create Retrieve Update Delete
[3] http://hibernate.sourceforge.net/
[4] http://jakarta.apache.org/ojb/

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: [RT] BEans And Forms Framework (BEAFF)

Posted by Sylvain Wallez <sy...@anyware-tech.com>.
Bertrand,

I have to read all this carefully, but a quick reading reveals a very 
interesting idea that I would like to point out to be sure people don't 
miss it : using Cocoon pipelines to "expand" relations betwen entities 
of the data model.

This is what is shown in your enumeration using the 
src="cocoon:/enums/styles.xml". You introduce this for enumerations 
only, but I think we should widen it to any kind of data type, as 
expanding relations is a major hassle when writing web applications and 
it is needed very often (building popups, master/detail views, etc).

More on this later (still late on projects I left before going to Ghent...)

Sylvain


Bertrand Delacretaz wrote:

>--- INTRO ---
>I think Torsten Curdt's GetTogether presentation [1] of the various ways of 
>writing webapps with Cocoon makes it clear that something better is needed to 
>write CRUD [2] applications with Cocoon.
>
>No-one wants to have to modify three configuration files in three different 
>languages every time a field is added to or removed from a form.
>
>Here's my suggestion for a simple framework for data entry and forms-to-beans 
>mapping. I think using this together with flowscript, Hibernate [3] or OJB 
>[4] for storage and XSLT for presentation would be all that is needed to 
>build CRUD webapps fairly easily and in a very scalable way.
>
>--- ASSUMPTIONS ---
>These describe how I'd like to build webapps. BEAFF (or elements of it) would 
>certainly be usable in other contexts but initial development should focus on 
>a simple environment.
>
>-Cocoon is used to build CRUD [2] applications. 
>
>-Business logic is implemented in backend java classes.
>
>-Java Beans (not EJB - normal java classes with Beans name conventions) are 
>used to hold data and interface with the backend.
>
>-Flowscript is used for flow control and interface between frontend (forms) 
>and backend (beans). 
>
>-Except for very simple stuff (required fields etc.), data validation is done 
>by the java backend. I don't want junior programmers working on flow changes 
>or page layout to risk breaking the business level validations, and backend 
>code and validations usually outlives the front-end and flow stuff, so it 
>makes sense for me to keep them together.
>
>--- BEAFF - THE PLAN ---
>-Use an XML-based data dictionary (DD) for fields, datatypes and beans 
>definitions. See example below.
>
>-DD can use enumerated types obtained in XML from Cocoon pipelines.
>
>-A Transformer creates form fields by replacing placeholder elements in pages 
>by appropriate labels (i18n-able) and data entry elements (HTML <input> and 
>the like) computed from the DD. Custom "field builders" can optionally be 
>used.
>
>-A Transformer populates forms values by using DD definitions to get data 
>from Beans. Custom mapping classes can optionally be used.
>
>-BEAFF classes are used (by the flowscript layer) to convert suitable HTTP 
>request parameters into the appropriate java data types based on DD mappings. 
>This includes basic validity checks (string-to-integer etc.). Custom mapping 
>classes can optionally be used.
>
>-BEAFF classes are used by the flowscript layer to move this converted data 
>into the beans, form-by-form, without having to explicitely write copying 
>code for each field. This uses java reflection mechanisms to be fully dynamic.
>
>-Beans classes are generated at compile-time by an ant task based on DD 
>information. Generated Beans include hook functions to allow data validation 
>and database interactions to happen in derived classes written by the 
>application programmer.
>
>--- EXAMPLE DD ---
>I don't know XForms and schema stuff very well, maybe these could be used 
>instead of a custom DD format. The aim here is to describe what must be in 
>the DD, not necessarily to be an implementation format.
>
><data-dictionary name="cd-library" java-package="myapp.beans">
>  <!-- custom data types -->
>  <data-types>
>    <data-type
>      name="musical-style"
>      class="beaff.enumeration" 
>      src="cocoon:/enums/styles.xml"
>      string-converter="myapp.formats.StyleFormatterAndParser"
>    >
>    </data-type>
>  </data-types>
>
>  <!-- reusable field definitions -->
>  <field-types>
>    <field-type name="artist" data-type="myapps.beans.Artist"/>
>  </field-types>
>
>  <!-- application data model -->
>  <beans>
>    <bean name="MusicCd">
>      <field data-type="java.lang.String" name="title" required="true"/>
>      <field data-type="musical-style" name="style"/>
>      <field data-type="artist" name="artist" required="true"/>
>    </bean>
>
>    <bean name="Artist">
>      <field data-type="java.lang.String" name="name" required="true"/>
>    </bean>
>  </beans>
>
></data-dictionary>
>
>I think this is sufficient to generate fields in forms, map beans values to 
>forms and map HTTP request parameters to beans. 
>
>Of course more DD options will be needed for custom formatters/parsers but 
>for a start the above should be sufficient.
>
>--- CODA ---
>I cannot imagine this doesn't exist yet, but I couldn't find a library that 
>does all that we need here. Suggestions?
>
>The power of BEAFF lies in the leverage given by the DD - changing DD info 
>updates all the required pieces of the application front-end (and backend 
>interface) with minimal effort.
>
>Other than that: fire away... ;-)
>
>  
>


-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }



---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: [RT] BEans And Forms Framework (BEAFF)

Posted by Bertrand Delacretaz <bd...@codeconsult.ch>.
On Tuesday 26 November 2002 13:53, Christian Haul wrote:
>. . .
> Perhaps the very same script could be used both for client side and
> server side validation.

Yes, a generated validation script could certainly be used in several ways.

>. . .
> > How about a "text-key" property on fields, that is used to build i18n
> > keys for the various messages?
>
> Good idea. Would it tie validation to i18n or could it still be used
> without it? That might be the charm of allowing arbitrary tags as
> error message.
>

I dont think this needs to be tied to i18n, a "text-key" could be expanded to 
retrieve messages from various sources.

-Bertrand

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: [RT] BEans And Forms Framework (BEAFF)

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 22.Nov.2002 -- 12:19 PM, Bertrand Delacretaz wrote:
> > The DD could be used to generate javascript code that does the
> > validation. 
> >. . .
> 
> Ok if you're speaking of server-side javascript. 
> Client-side javascript validations are too risky IMHO except for 
> "pre-validations" that cause no harm to the business data if they don't run 
> as expected or are hacked away by malicious users.

Perhaps the very same script could be used both for client side and
server side validation.

> > The DD should / could contain error messages as well. AFAIK xforms
> > does that already. Two types of error messages would be nice: a "short
> > error" and a "long error".
> >. . .
> 
> How about a "text-key" property on fields, that is used to build i18n keys 
> for the various messages?

Good idea. Would it tie validation to i18n or could it still be used
without it? That might be the charm of allowing arbitrary tags as
error message.

	Chris.
-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: [RT] BEans And Forms Framework (BEAFF)

Posted by Bertrand Delacretaz <bd...@codeconsult.ch>.
Hi Christian, thanks for the input!

>. . .
> If the classes are only used to hold data, that could be done with a
> DOM-like structure as well. Access could be done through jxpath.
>. . .

You're right - I've been going for the java beans version with the idea of 
writing as much of the "important" code in java rather than scripting. I 
think both approaches are valid depending on one's preferences and 
environment.

Of course if the DD model is good enough, both ways could be implemented if 
needed and depending on how much effort is put into this.

>. . .
> The DD could be used to generate javascript code that does the
> validation. 
>. . .

Ok if you're speaking of server-side javascript. 
Client-side javascript validations are too risky IMHO except for 
"pre-validations" that cause no harm to the business data if they don't run 
as expected or are hacked away by malicious users.

I think validation could be added later on to BEAFF, a first version without 
it could be usable already, with some additional effort.

>. . .
> The DD should / could contain error messages as well. AFAIK xforms
> does that already. Two types of error messages would be nice: a "short
> error" and a "long error".
>. . .

How about a "text-key" property on fields, that is used to build i18n keys 
for the various messages?

  <field name="artist" text-key="musiccd.artist"/>

Then, i18n messages use well-known prefixes suffixes:

  field.short-name.musiccd.artist = Artist
  field.long-name.musiccd.artist = Artist who sings or play on the CD
  field.tooltip musiccd.artist = Enter name of artist
  field.error.musiccd.artist.charset = Invalid characters in artist name

This allows the DD to be focused on the actual data model while allowing many 
different messages.

-Bertrand

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: [RT] BEans And Forms Framework (BEAFF)

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 21.Nov.2002 -- 10:04 AM, Bertrand Delacretaz wrote:
> I think Torsten Curdt's GetTogether presentation [1] of the various ways of 
> writing webapps with Cocoon makes it clear that something better is needed to 
> write CRUD [2] applications with Cocoon.
> 
> No-one wants to have to modify three configuration files in three different 
> languages every time a field is added to or removed from a form.
> 
> Here's my suggestion for a simple framework for data entry and forms-to-beans 
> mapping. I think using this together with flowscript, Hibernate [3] or OJB 
> [4] for storage and XSLT for presentation would be all that is needed to 
> build CRUD webapps fairly easily and in a very scalable way.
> 
> These describe how I'd like to build webapps. BEAFF (or elements of it) would 
> certainly be usable in other contexts but initial development should focus on 
> a simple environment.
> 
> -Cocoon is used to build CRUD [2] applications. 
> 
> -Business logic is implemented in backend java classes.
> 
> -Java Beans (not EJB - normal java classes with Beans name conventions) are 
> used to hold data and interface with the backend.
> 
> -Flowscript is used for flow control and interface between frontend (forms) 
> and backend (beans). 
> 
> -Except for very simple stuff (required fields etc.), data validation is done 
> by the java backend. I don't want junior programmers working on flow changes 
> or page layout to risk breaking the business level validations, and backend 
> code and validations usually outlives the front-end and flow stuff, so it 
> makes sense for me to keep them together.
> 
> -Use an XML-based data dictionary (DD) for fields, datatypes and beans 
> definitions. See example below.
> 
> -DD can use enumerated types obtained in XML from Cocoon pipelines.
> 
> -A Transformer creates form fields by replacing placeholder elements in pages 
> by appropriate labels (i18n-able) and data entry elements (HTML <input> and 
> the like) computed from the DD. Custom "field builders" can optionally be 
> used.
> 
> -A Transformer populates forms values by using DD definitions to get data 
> from Beans. Custom mapping classes can optionally be used.
> 
> -BEAFF classes are used (by the flowscript layer) to convert suitable HTTP 
> request parameters into the appropriate java data types based on DD mappings. 
> This includes basic validity checks (string-to-integer etc.). Custom mapping 
> classes can optionally be used.
> 
> -BEAFF classes are used by the flowscript layer to move this converted data 
> into the beans, form-by-form, without having to explicitely write copying 
> code for each field. This uses java reflection mechanisms to be fully dynamic.

If the classes are only used to hold data, that could be done with a
DOM-like structure as well. Access could be done through jxpath.

> -Beans classes are generated at compile-time by an ant task based on DD 
> information. Generated Beans include hook functions to allow data validation 
> and database interactions to happen in derived classes written by the 
> application programmer.

Personally, I prefer the configuration approach. This allows to put
everything in a database and have dynamic forms.

The DD could be used to generate javascript code that does the
validation. Since the client understands javascript (or nothing) the
generated scripts can be used for client side validation as well. We
are already in the great position to be able to write actions in
javascript IIRC. So feeding this generated code to a javascript action
could be used to do the actual validation.

Of course I'd be happy as well if some java was produced and compiled
on the fly. Many clients can use java for form validation as well.

> 
> I don't know XForms and schema stuff very well, maybe these could be used 
> instead of a custom DD format. The aim here is to describe what must be in 
> the DD, not necessarily to be an implementation format.
> 
> <data-dictionary name="cd-library" java-package="myapp.beans">
>   <!-- custom data types -->
>   <data-types>
>     <data-type
>       name="musical-style"
>       class="beaff.enumeration" 
>       src="cocoon:/enums/styles.xml"
>       string-converter="myapp.formats.StyleFormatterAndParser"
>     >
>     </data-type>
>   </data-types>
> 
>   <!-- reusable field definitions -->
>   <field-types>
>     <field-type name="artist" data-type="myapps.beans.Artist"/>
>   </field-types>
> 
>   <!-- application data model -->
>   <beans>
>     <bean name="MusicCd">
>       <field data-type="java.lang.String" name="title" required="true"/>
>       <field data-type="musical-style" name="style"/>
>       <field data-type="artist" name="artist" required="true"/>
>     </bean>
> 
>     <bean name="Artist">
>       <field data-type="java.lang.String" name="name" required="true"/>
>     </bean>
>   </beans>
> 
> </data-dictionary>

The DD should / could contain error messages as well. AFAIK xforms
does that already. Two types of error messages would be nice: a "short
error" and a "long error".

> I think this is sufficient to generate fields in forms, map beans values to 
> forms and map HTTP request parameters to beans. 
> 
> Of course more DD options will be needed for custom formatters/parsers but 
> for a start the above should be sufficient.
> 
> I cannot imagine this doesn't exist yet, but I couldn't find a library that 
> does all that we need here. Suggestions?
> 
> The power of BEAFF lies in the leverage given by the DD - changing DD info 
> updates all the required pieces of the application front-end (and backend 
> interface) with minimal effort.
> 
> Other than that: fire away... ;-)

	Chris.
-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org