bug 1954 - was assuming keys would be passed in, and of course they aren't on creation.

This commit is contained in:
sb 2008-06-10 08:51:16 +00:00
parent 090268cdbd
commit 2e9aa81fe5

View file

@ -9,8 +9,8 @@
Transform ADL into (partial) controller classes Transform ADL into (partial) controller classes
$Author: sb $ $Author: sb $
$Revision: 1.12 $ $Revision: 1.13 $
$Date: 2008-06-09 15:52:07 $ $Date: 2008-06-10 08:51:16 $
--> -->
<!-- WARNING WARNING WARNING: Do NOT reformat this file! <!-- WARNING WARNING WARNING: Do NOT reformat this file!
@ -67,7 +67,7 @@
// //
// Automatically generated abstract super class for controllers for the // Automatically generated abstract super class for controllers for the
// <xsl:value-of select="/adl:application/@name"/> application; generated using // <xsl:value-of select="/adl:application/@name"/> application; generated using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.12 $', 10)"/> // adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.13 $', 10)"/>
// //
// This file is automatically generated; DO NOT EDIT IT. // This file is automatically generated; DO NOT EDIT IT.
// //
@ -133,7 +133,7 @@
// //
// Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s // Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s
// Automatically generated from application description using // Automatically generated from application description using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.12 $', 10)"/> // adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.13 $', 10)"/>
// //
// This file is automatically generated; DO NOT EDIT IT. // This file is automatically generated; DO NOT EDIT IT.
// //
@ -290,6 +290,7 @@
AssertUserCanCreate(); AssertUserCanCreate();
try { try {
if ( AllKeys()) {
record = new <xsl:value-of select="concat($entityns, '.', @name)"/>(<xsl:for-each select="adl:key/adl:property"> record = new <xsl:value-of select="concat($entityns, '.', @name)"/>(<xsl:for-each select="adl:key/adl:property">
<xsl:variable name="basetype"> <xsl:variable name="basetype">
<xsl:call-template name="base-type"> <xsl:call-template name="base-type">
@ -328,6 +329,11 @@
</xsl:choose> </xsl:choose>
</xsl:for-each>); </xsl:for-each>);
} }
else
{
record = new <xsl:value-of select="concat($entityns, '.', @name)"/>();
}
}
catch ( FormatException) { catch ( FormatException) {
/* failed to parse a number - not wholly unexpected, since it's most likely /* failed to parse a number - not wholly unexpected, since it's most likely
* that an empty string was passed in */ * that an empty string was passed in */
@ -673,27 +679,33 @@
} }
</xsl:if> </xsl:if>
/// &lt;summary&gt;
/// Check whether values for all my keys are available in the form fields
/// &lt;/summary&gt;
protected bool AllKeys() {
/* whether we have valid values for all the key fields */
bool result = true;
<xsl:for-each select="adl:key/adl:property">
if ( String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])) {
result = false;
} else if ( "<xsl:value-of select="concat('$instance.', @name)"/>".Equals( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])) {
/* nasty artefact of NVelocity forms - default 'null value' is dollar followed by fieldname */
result = false;
}
</xsl:for-each>
return result;
}
/// &lt;summary&gt; /// &lt;summary&gt;
/// Fetch the record represented by the values in the current Form /// Fetch the record represented by the values in the current Form
/// &lt;/summary&gt; /// &lt;/summary&gt;
protected <xsl:value-of select="concat($entityns, '.', @name)"/> FetchRecord(ISession hibernator) { protected <xsl:value-of select="concat($entityns, '.', @name)"/> FetchRecord(ISession hibernator) {
/* the instance (record) of type <xsl:value-of select="@name"/> we're dealing with */ /* the instance (record) of type <xsl:value-of select="@name"/> we're dealing with */
<xsl:value-of select="concat($entityns, '.', @name)"/> record = null; <xsl:value-of select="concat($entityns, '.', @name)"/> record = null;
/* whether we have valid values for all the key fields */
bool allkeys = true;
/* check whether values for all key slots have been passed in; if so, we're probably dealing with an if ( AllKeys()){
* existing record */
<xsl:for-each select="adl:key/adl:property">
if ( String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])) {
allkeys = false;
} else if ( "<xsl:value-of select="concat('$instance.', @name)"/>".Equals( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])) {
/* nasty artefact of NVelocity forms - default 'null value' is dollar followed by fieldname */
allkeys = false;
}
</xsl:for-each>
if ( allkeys){
/* it's (probably) existing, retrieve it */ /* it's (probably) existing, retrieve it */
record = hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', @name)"/>)) record = hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', @name)"/>))
<xsl:for-each select="adl:key/adl:property"> <xsl:for-each select="adl:key/adl:property">