ColdFusion:简单的CFGRIDUPDATE验证



我尝试使用非常 simple cfgrid(使用cfgridupdate),但不允许nulls。

<cfset strWarning= "">  
<cfif IsDefined("FORM.gridEntered")> 
    <cfif FORM.myName EQ '' OR FORM.myURL EQ ''>
        <cfset strWarning= "Error: Form fields cannot be blank">
    <cfelse>
        <cfgridupdate grid="gridSomething" 
          dataSource="qryTSQL" tableName="tblName" keyOnly="Yes"> 
    </cfif> 
</cfif> 
<cfoutput>#strWarning#</cfoutput><br />
<cfform> 
<cfgrid name="gridSomething" query="qryTSQL" 
       selectMode="Edit" format="HTML">  
    <cfgridcolumn name = "myID" display="No"> 
    <cfgridcolumn name = "myName">
    <cfgridcolumn name = "myURL"> 
</cfgrid> 
<cfinput type="submit" name="gridEntered"> 

我遇到的错误是 - 错误诊断:复杂的对象类型无法转换为简单值。该表达式已将变量或中间表达式结果作为简单值。但是,结果无法转换为简单的值。简单的值是字符串,数字,布尔值和日期/时间值。查询,数组和com对象是复杂值的示例。该错误最有可能的原因是您尝试将复杂的值用作简单的值。例如,您尝试在CFIF标签中使用查询变量。

我想我正在想这个所需的解决方案。

谢谢。

编辑:更新错误消息

错误诊断:元素myurl未定义。

Form scope - struct
FIELDNAMES  GRIDENTERED,__CFGRID__CFFORM_1__GRIDSOMETHING
GRIDENTERED Submit Query
GRIDSOMETHING.MYID  Form scope - array 
1   1001 
GRIDSOMETHING.MYURL Form scope - array 
1   /test_d.cfm 
GRIDSOMETHING.ORIGINAL.MYID Form scope - array 
1   1001 
GRIDSOMETHING.ORIGINAL.MYURL    Form scope - array 
1   /changed.cfm 
GRIDSOMETHING.ROWSTATUS.ACTION  Form scope - array 
1   U 
__CFGRID__CFFORM_1__GRIDSOMETHING   __CFGRID__EDIT__=2 MYID Y MYURL Y 1 U 1001 1001 /test_d.cfm /changed.cfm 

网格的工作方式与标准FORM字段不同。由于网格包含多个数据行,因此CF创建了新/更改值的数组。每个网格列IE

一个
     FORM.gridname.columnName

要确定特定列的值的任何是否为空的是空的,您需要遍历该列的数组并检查每个值:

    <cfset updateCount = arrayLen(FORM.gridSomething.myName) />
    <cfloop from="1" to="#updateCount#" index="x">
         <cfset nameValue = trim( FORM.gridSomething.myName[x] ) />
         <cfset urlValue  = trim( FORM.gridSomething.myURL[x]) ) />
         <!--- one or both of the values is empty --->
         <cfif not len( nameValue ) OR not len( urlValue )>
             ... empty value found. do something here ....
         </cfif>
    </cfloop>

将此函数添加到您的代码中,并将其称为将其传递为表单范围,如下所示;在页面或CFC上的工作相同!用一些版本的CF清除错误,这些版本在简单的网格更新中在空白col上cho

    <cffunction name="cleanGridUpdate" >
        <cfargument name="FORM" >
        <cfloop collection="#FORM#" item="thisOne">
        <cftry>
            <cfset thisDeep = arrayLen(FORM[thisOne])>
                <cfloop index="x" from="1" to="#thisDeep#">
                    <cfif len(FORM[thisOne][x])lt 1>
                        <cfset FORM[thisOne][x] = javaCast( "null", 0 )>
                    </cfif>
                </cfloop>               
            <cfcatch>
                <cfset cat=1>   
            </cfcatch>
          </cftry>
          </cfloop>
         <cfreturn form>
     </cffunction>
    <cfif isDefined('URL.action') AND URL.action eq 'gridUpdate'>
       <cfset cleanGridUpdate(FORM)>
       <cfgridupdate grid="#URL.table#" table="#URL.table#" datasource="your_DS" 
        keyonly="yes" > 
    </cfif>

    <cfform action="##?action=gridUpdate&table=cheesePuffs" method="post">
       <cfgrid name='cheesePuffs' format='HTML'/>
       <cfinput name="submit" type="submit" value>
    </cfform>

最新更新