Link to home
Start Free TrialLog in
Avatar of Panos
PanosFlag for Germany

asked on

cfwindow-cfgrid-cfgridupdate problem

Hello experts.
I m using cfwindow and cfgrid with cfgridupdate.
If i submit the form without changing any field i have an error:The cfgridupdate tag cannot find the grid named Kategorie.
If i make any change and submit the form I get an error:
 Primary key not found for the Kategorie table.
The table you are attempting to update, Kategorie does not have a primary key, which is a field or set of fields that uniquely identify each record..Any help?
(i'm using cf8 and mysql)

<a href="#" onclick="ColdFusion.navigate('includes/body.cfm?action=categories', 'getfilespage'); ColdFusion.Window.show('getfilespage');">Categories</a><br>



<cfwindow center="true"
          name="getfilespage"
          minHeight="150" 
          minWidth="150" 
          title="Body" 
          initshow="false"
          modal="true"/>


the body.cfm
<cfif url.action EQ 'categories'>
<cfif IsDefined("form.gridEntered") is True>
   <cfgridupdate grid = "Kategorie" dataSource = "#request.dsn#" Keyonly="true" tableName = "Kategorie">
 </cfif>

<cfquery name="q_Kategorie" datasource="#request.dsn#">
SELECT Kat_Text,Kat_ID,langid,mobiles_sub_id
FROM <!---dbo.--->Kategorie
ORDER BY Kat_ID ASC 
</cfquery>
 <cfform>
   <cfgrid name="Kategorie" format="html" query="q_Kategorie" pagesize="7" insert = "Yes"  delete = "Yes" sort="yes"
 selectmode="edit">
      <cfgridcolumn name="Kat_ID" header="ID" width="30"/>
      <cfgridcolumn name="Kat_Text" header="Text" width="120"/>
      <cfgridcolumn name="mobiles_sub_id" header="Mobile" width="40"/>
      <cfgridcolumn name="LangID" header="LangID" width="40"/>
   </cfgrid>
   <cfinput type="submit" name="gridEntered">

</cfform>
</cfif>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Panos

ASKER

Hi agx.
I dump the form but i get the coldfusion errormessage.
using cfdebug i get this error:error:http: Error retrieving markup for element getfilespage_body : Internal Server Error

No, I mean just dump the scope normally, using CFDUMP

<cfdump var="#FORM#">
<cfif IsDefined("form.gridEntered") is True>
Avatar of Panos

ASKER

I did exactly this.
when the cfwincow opens it shows struct [empty] and when i hit the submit button i get the error:The cfgridupdate tag cannot find the grid named Kategorie.
One of us is misunderstanding something ;-)  

In order to see what values are sent when the form is submitted, you need to place cfdump code BEFORE the cfif/cfgridupdate code.  Otherwise, an error happens and the results are never shown.

<cfif url.action EQ 'categories'>
    <CFDUMP VAR="#FORM#">             <!--- MUST be placed before the grid update --->

    <cfif IsDefined("form.gridEntered") is True>
           <cfgridupdate grid = "Kategorie" dataSource = "#request.dsn#" Keyonly="true" tableName = "Kategorie">
     </cfif>

</cfif>


Avatar of Panos

ASKER

Here is my code:
<cfif url.action EQ 'categories'>
<cfdump var="#FORM#">
  <cfif IsDefined("form.gridEntered") is True>
   <cfgridupdate grid = "Kategorie" dataSource = "#request.dsn#" Keyonly="true" tableName = "Kategorie">
  </cfif>
   <cfquery name="q_Kategorie" datasource="#request.dsn#">
   SELECT Kat_Text,Kat_ID,langid,mobiles_sub_id
   FROM <!---dbo.--->Kategorie
   ORDER BY Kat_ID ASC
   </cfquery>
  <cfform>
   <cfgrid name="Kategorie" format="html" query="q_Kategorie" pagesize="7" insert = "Yes"  delete = "Yes" sort="yes"
    rowheaderbold="yes" colHeaderBold = "Yes"  selectmode="edit" pictureBar="yes" hspace="0" vspace="0" autowidth="yes">
      <cfgridcolumn name="Kat_ID" header="ID" width="30"/>
      <cfgridcolumn name="Kat_Text" header="Text" width="120"/>
      <cfgridcolumn name="mobiles_sub_id" header="Mobile" width="40"/>
      <cfgridcolumn name="LangID" header="LangID" width="40"/>
   </cfgrid>
   <cfinput type="submit" name="gridEntered">
  </cfform>
</cfif>
Avatar of Panos

ASKER

The other mistery i have is that when i add in the query the column with the primary key(table_id)
i get the error:[Macromedia][SQLServer JDBC Driver][SQLServer]Invalid column name 'table_id'.
Avatar of Panos

ASKER

part of mysql table-settings
screen.gif
>> Here is my code:

   Oh, I misunderstood then.  You're saying when you do that the FORM is totally empty?
   Try the exact same code, but without the <cfwindow>.  I'm wondering if cfwindow is messing
   things up.  



Avatar of Panos

ASKER

agx i get the same errors.
Maybe i did something wrong in the mysql table.
Avatar of Panos

ASKER

when imake a change and submit the form:
 Primary key not found for the Kategorie table.
The table you are attempting to update, Kategorie does not have a primary key, which is a field or set of fields that uniquely identify each record.
Avatar of Panos

ASKER

Here is  my new error:
 Primary key(s) table_id not found.
The cfgridupdate tag cannot update or delete the row because it cannot find the primary key(s) table_id in the cfgrid form fields for table Kategorie in datasource....
Avatar of Panos

ASKER

Agx.
Finally a part is working.I add the table_id in the cfgrid but i need it as a hidden field.
<cfform>
   <cfgrid name="Kategorie" format="html" query="q_Kategorie" pagesize="7" insert = "Yes"  delete = "Yes" sort="yes"
    rowheaderbold="yes" colHeaderBold = "Yes"  selectmode="edit" pictureBar="yes" hspace="0" vspace="0" autowidth="yes">
      <cfgridcolumn name="Kat_ID" header="ID" width="30"/>
      <cfgridcolumn name="Kat_Text" header="Text" width="120"/>
      <cfgridcolumn name="mobiles_sub_id" header="Mobile" width="40"/>
      <cfgridcolumn name="LangID" header="LangID" width="40"/>
      <cfgridcolumn name="table_id" header="Table_id" width="40"/>
   </cfgrid>
   <cfinput type="submit" name="gridEntered_kat">
  </cfform>

Now if i make changes and submit the form i have no errors.
If i submit the form without making a change i get the error:
The cfgridupdate tag cannot find the grid named Kategorie.
Ok, but is the "table_id" actually defined as the PRIMARY KEY in your table?  If not, that sounds like the problem.  Can script out the mySQL table and post the definition? ie  the CREATE TABLE ...(  statement.
Sorry, our posts overlapped. Disregard my last response.
Avatar of Panos

ASKER

CREATE TABLE `kategorie` (
  `table_id` int(11) NOT NULL AUTO_INCREMENT,
  `Kat_ID` int(11) DEFAULT '0',
  `Kat_Text` varchar(50) DEFAULT '',
  `LangID` int(11) DEFAULT '0',
  `Mobiles_sub_ID` int(11) DEFAULT '0',
  PRIMARY KEY (`table_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=89 DEFAULT CHARSET=utf8
>> Finally a part is working.I add the table_id in the cfgrid but i need it as a hidden field.

Now that the basic code is functioning, does it work once you put the cfwindow back in?
Avatar of Panos

ASKER

agx i'm back it was too late for me on my last comment.

there is a misfunction using cfwindow It is not updating the correct row.
Avatar of Panos

ASKER

Disregard my last post.
It is the first time i use cfgrid and unfortunately i'm using it in a wrong way.I did  wrong updated  row because i was selecting before submitting another row to deselect the altered row field.Now i'm clicking on the white space and have no mistaces.The only error that remains is if i have not make any change.
Avatar of Panos

ASKER

agx.
Finally i did solve my problem using cfgridaction instead of cfgridupdate.
and for a more complex example i followed the tutorial on this page:http://www.coldfusion-ria.com/Blog/index.cfm/2009/1/21/ColdFusion-8-cfgrid-adding-Add-and-Delete-Record-Functionality where i did add the edit function.
I post a working code below for the first example:
<cfquery name="q_Geschlecht" datasource="#request.dsn#">
    SELECT geschlecht_text ,geschlecht_ID,langid
    FROM t_geschlecht
    </cfquery>
   <cfform>
    <cfgrid name="Geschlecht" format="html" pagesize="30"   delete = "Yes" sort="yes" 
    rowheaderbold="yes" colHeaderBold = "Yes"    pictureBar="yes" hspace="0" vspace="0"  bind="cfc:cfc.geschlecht.getGeschlecht({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})" selectmode="edit" onchange= "cfc:cfc.geschlecht.updateGeschlecht({cfGridAction},{cfgridrow},{cfgridchanged})">
      <cfgridcolumn name="geschlecht_ID" header="ID" width="30"/>
      <cfgridcolumn name="geschlecht_text" header="Text" width="120"/>
      <cfgridcolumn name="LangID" header="LangID" width="40"/>
      <cfgridcolumn name="table_id" header="Table_id"  select="no"/>
    </cfgrid>
  </cfform>

the cfc:
<cffunction name="getgeschlecht" access="remote">
      <cfargument name="page" required="yes">
      <cfargument name="pageSize" required="yes">
      <cfargument name="gridsortcolumn" required="yes">
      <cfargument name="gridsortdirection" required="yes">
    <cfquery name="q_geschlecht" datasource="#request.dsn#">
    SELECT geschlecht_text ,geschlecht_ID,langid,table_id
    FROM <!---dbo.--->t_geschlecht
    <cfif gridsortcolumn neq ''>
      order by #gridsortcolumn# #gridsortdirection#
     </cfif>
    </cfquery>
   <cfreturn queryconvertforgrid(q_geschlecht,page,pagesize)/>
</cffunction>
<cffunction name="updategeschlecht" access="remote">
      <cfargument name="gridaction" type="string" required="yes">
      <cfargument name="gridrow" type="struct" required="yes">
      <cfargument name="gridchanged" type="struct" required="yes">
      <cfset var colname = "">
      <cfset var value = "">
 <cfswitch expression="#arguments.gridaction#">
     <!--- update --->
   <cfcase value="U">
    <cfset colname = StructKeyList(arguments.gridchanged)>
    <cfset value = arguments.gridchanged[colname]>

      <cfquery datasource="#request.dsn#">
        UPDATE t_geschlecht
        SET #colname# = '#value#'
        WHERE table_id = <cfqueryparam value="#arguments.gridrow.table_id#" cfsqltype="cf_sql_integer">
       </cfquery>
     </cfcase>
     <!--- delete --->
      <cfcase value="D">
       <cfquery datasource="#request.dsn#">
       DELETE FROM t_geschlecht
       where table_id = <cfqueryparam value="#arguments.gridrow.table_id#" cfsqltype="cf_sql_integer">
       </cfquery>
      </cfcase>
     </cfswitch>
</cffunction>

Open in new window

Avatar of Panos

ASKER

Thank you
regards
panos