Skip to content

Instantly share code, notes, and snippets.

@dustinmartin
Created April 29, 2011 00:36
Show Gist options
  • Select an option

  • Save dustinmartin/947636 to your computer and use it in GitHub Desktop.

Select an option

Save dustinmartin/947636 to your computer and use it in GitHub Desktop.

Revisions

  1. Dustin Martin revised this gist Apr 29, 2011. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.cfm
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    <cfscript>
    public void function populate(required struct memento,
    boolean trustedSetter=false,
    string include="",
    string exclude="",
    string disallowConversionToNull=""){
    boolean trustedSetter=false,
    string include="",
    string exclude="",
    string disallowConversionToNull=""){
    var object = this;
    var key = "";
  2. Dustin Martin revised this gist Apr 29, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.cfm
    Original file line number Diff line number Diff line change
    @@ -46,6 +46,6 @@ public void function populate(required struct memento,
    }
    }
    }
    } // End for loop
    }
    }
    </cfscript>
  3. Dustin Martin revised this gist Apr 29, 2011. 2 changed files with 4 additions and 4 deletions.
    4 changes: 2 additions & 2 deletions gistfile2.cfm
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    <cfscript>
    if(form.value== ""){
    object.setValue1( javacast("null","") );
    object.setValue1( javacast("null","") );
    }
    else {
    object.setValue1(form.value);
    object.setValue1(form.value);
    }
    </cfscript>
    4 changes: 2 additions & 2 deletions gistfile4.cfm
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    <cfscript>
    object.populate(
    memento = form,
    disallowConversionToNull = "someProperty,anotherProperty"
    memento = form,
    disallowConversionToNull = "someProperty,anotherProperty"
    );
    </cfscript>
  4. Dustin Martin revised this gist Apr 29, 2011. 1 changed file with 47 additions and 47 deletions.
    94 changes: 47 additions & 47 deletions gistfile1.cfm
    Original file line number Diff line number Diff line change
    @@ -1,51 +1,51 @@
    <cfscript>
    public void function populate(required struct memento,
    boolean trustedSetter=false,
    string include="",
    string exclude="",
    string disallowConversionToNull=""){
    var object = this;
    var key = "";
    var populate = true;
    // Populate Bean
    for(key in memento){
    populate = true;
    // Include List?
    if( len(include) AND NOT listFindNoCase(include,key) ){
    populate = false;
    }
    // Exclude List?
    if( len(exclude) AND listFindNoCase(exclude,key) ){
    populate = false;
    }
    // Populate?
    if( populate ){
    // Check if the setter exists or if trusted setting is on
    if( structKeyExists(object,"set" & key) or trustedSetter ){
    // If the value is blank it might be converted to null
    if( isSimpleValue(memento[key]) && trim(memento[key]) == "" ){
    // Check if this value should be kept as a string instead of converted to null
    if( len(disallowConversionToNull) AND NOT listFindNoCase(disallowConversionToNull,key) ){
    evaluate("object.set#key#(memento[key])");
    }
    else {
    // Set the value to null
    evaluate('object.set#key#(javacast("null",""))');
    }
    }
    else {
    evaluate("object.set#key#(memento[key])");
    }
    }
    }
    } // End for loop
    boolean trustedSetter=false,
    string include="",
    string exclude="",
    string disallowConversionToNull=""){
    var object = this;
    var key = "";
    var populate = true;
    // Populate Bean
    for(key in memento){
    populate = true;
    // Include List?
    if( len(include) AND NOT listFindNoCase(include,key) ){
    populate = false;
    }
    // Exclude List?
    if( len(exclude) AND listFindNoCase(exclude,key) ){
    populate = false;
    }
    // Populate?
    if( populate ){
    // Check if the setter exists or if trusted setting is on
    if( structKeyExists(object,"set" & key) or trustedSetter ){
    // If the value is blank it might be converted to null
    if( isSimpleValue(memento[key]) && trim(memento[key]) == "" ){
    // Check if this value should be kept as a string instead of converted to null
    if( len(disallowConversionToNull) AND NOT listFindNoCase(disallowConversionToNull,key) ){
    evaluate("object.set#key#(memento[key])");
    }
    else {
    // Set the value to null
    evaluate('object.set#key#(javacast("null",""))');
    }
    }
    else {
    evaluate("object.set#key#(memento[key])");
    }
    }
    }
    } // End for loop
    }
    </cfscript>
  5. Dustin Martin revised this gist Apr 29, 2011. 3 changed files with 9 additions and 3 deletions.
    4 changes: 3 additions & 1 deletion gistfile2.cfm
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    <cfscript>
    if(form.value== ""){
    object.setValue1( javacast("null","") );
    }
    else {
    object.setValue1(form.value);
    }
    }
    </cfscript>
    4 changes: 3 additions & 1 deletion gistfile3.cfm
    Original file line number Diff line number Diff line change
    @@ -1 +1,3 @@
    object.populate(form);
    <cfscript>
    object.populate(form);
    </cfscript>
    4 changes: 3 additions & 1 deletion gistfile4.cfm
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    <cfscript>
    object.populate(
    memento = form,
    disallowConversionToNull = "someProperty,anotherProperty"
    );
    );
    </cfscript>
  6. Dustin Martin revised this gist Apr 29, 2011. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion gistfile1.cfm
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <cfscript>
    public void function populate(required struct memento,
    boolean trustedSetter=false,
    string include="",
    @@ -46,4 +47,5 @@ public void function populate(required struct memento,
    }
    }
    } // End for loop
    }
    }
    </cfscript>
  7. Dustin Martin revised this gist Apr 29, 2011. No changes.
  8. Dustin Martin created this gist Apr 29, 2011.
    49 changes: 49 additions & 0 deletions gistfile1.cfm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    public void function populate(required struct memento,
    boolean trustedSetter=false,
    string include="",
    string exclude="",
    string disallowConversionToNull=""){

    var object = this;
    var key = "";
    var populate = true;

    // Populate Bean
    for(key in memento){
    populate = true;

    // Include List?
    if( len(include) AND NOT listFindNoCase(include,key) ){
    populate = false;
    }

    // Exclude List?
    if( len(exclude) AND listFindNoCase(exclude,key) ){
    populate = false;
    }

    // Populate?
    if( populate ){

    // Check if the setter exists or if trusted setting is on
    if( structKeyExists(object,"set" & key) or trustedSetter ){

    // If the value is blank it might be converted to null
    if( isSimpleValue(memento[key]) && trim(memento[key]) == "" ){

    // Check if this value should be kept as a string instead of converted to null
    if( len(disallowConversionToNull) AND NOT listFindNoCase(disallowConversionToNull,key) ){
    evaluate("object.set#key#(memento[key])");
    }
    else {
    // Set the value to null
    evaluate('object.set#key#(javacast("null",""))');
    }
    }
    else {
    evaluate("object.set#key#(memento[key])");
    }
    }
    }
    } // End for loop
    }
    6 changes: 6 additions & 0 deletions gistfile2.cfm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    if(form.value== ""){
    object.setValue1( javacast("null","") );
    }
    else {
    object.setValue1(form.value);
    }
    1 change: 1 addition & 0 deletions gistfile3.cfm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    object.populate(form);
    4 changes: 4 additions & 0 deletions gistfile4.cfm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    object.populate(
    memento = form,
    disallowConversionToNull = "someProperty,anotherProperty"
    );