• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Composant cfc ou include

New Here ,
Sep 11, 2018 Sep 11, 2018

Copy link to clipboard

Copied

Bonjour,

Je cherche à faire un composant ou un include pour faire une table qui alimente une autre table ( Pays - ville).

Etant débutant, j'ai trouvé du code sur un site mais malheureusement ...

<cfcomponent>

<cfform name="mycfform">

  <CFQUERY datasource="#session.dbname#" name="AddTable">

SELECT

Pays,

Ville

FROM Monde

WHERE sitename='#session.site#'

  <cfselect name="#Pays#" bind="cfc:bindFcns.getpays()" bindonload="true">

  <option name="0">--#Pays#--</option>

  </cfselect>

  <cfselect name="#Ville#" bind="cfc:bindFcns.getvilles({#pays#})">

  <option name="0">--#ville#--</option>

  </cfselect>

  </CFQUERY>

</cfform>

</cfcomponent>

Merci par avance

Marc

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 06, 2018 Oct 06, 2018

Oh, two more things, just in case you need them:

1) to display multiple items in the select list, use the size attribute.

2) remove the <br> tag to display the lists side by side.

For example, the following will display a maximum of 5 countries and 8 cities:

<cfselect name="pays" bind="cfc:Cfc.bindFcns.getPays()" bindonload="true" size="5"/>

<cfselect name="ville" bind="cfc:Cfc.bindFcns.getVilles({pays})" size="8"/>

Votes

Translate

Translate
New Here ,
Sep 13, 2018 Sep 13, 2018

Copy link to clipboard

Copied

Pas d'aide ???

Marc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 16, 2018 Sep 16, 2018

Copy link to clipboard

Copied

I am trying to make a component or an include to make a table that feeds another table (Country - city).

Exemple.gif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 16, 2018 Sep 16, 2018

Copy link to clipboard

Copied

bindFcns.cfc

<cfcomponent>

<cffunction name="getPays" access="remote" returntype="array">

    <cfset var paysQry = "">

     <cfset var paysArray = arrayNew(2)>

    <cfquery name = "paysQry" dataSource = "#session.dbname#">

    SELECT Pays

    FROM Monde

    WHERE sitename=<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.site#">

    ORDER BY pays

    </cfquery>

    <!--- Values for the first (the default) select option --->

    <cfset anneeArray[1][1]="">

    <cfset anneeArray[1][2]="Sélectionnez un pays">

    <cfloop query="paysQry">

    <cfset anneeArray[currentrow+1][1]=paysQry.pays>

    <cfset anneeArray[currentrow+1][2]=paysQry.pays>

    </cfloop>

    <cfreturn paysArray>

</cffunction>

<cffunction name="getVilles" access="remote" returntype="array">

    <cfargument name="cePays" required="true" type="string">

    <cfset var villesQry = "">

    <cfset var villesArray = arrayNew(2)>

    <cfquery name = "villesQry" dataSource = "#session.dbname#">

    SELECT ville

    FROM Monde

    WHERE pays = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.cePays#">

    ORDER BY ville  

    </cfquery>

    <!--- Values for the first (the default) select option --->

    <cfset villesArray[1][1]="">

    <cfset villesArray[1][2]="Sélectionnez une ville">

    <cfloop query="villesQry">

    <cfset villesArray[currentrow+1][1]=villesQry.ville>

    <cfset villesArray[currentrow+1][2]=villesQry.ville>

    </cfloop>

    <cfreturn villesArray>

</cffunction>

</cfcomponent>

villes.cfm

<cfform name="villesEtPays">

  <cfselect name="pays" bind="cfc:bindFcns.getPays()" bindonload="true" />

<br>

  <cfselect name="ville" bind="cfc:bindFcns.getVilles({pays})" />

</cfform>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 17, 2018 Sep 17, 2018

Copy link to clipboard

Copied

Bonjour,

Avant tout merci pour cela.

Mais malheureusement j'ai encore un soucis car j'ai ce message :

bing failed for select box country. bing value is not a 2D array or valid serialized query.

J'ai mis mon Cfc dans une directory Cfc à la racine.

Merci par avance

Cordialement

Hello,

First of all thank you for that.

But unfortunately I still have a problem because I have this message:

failed box for select box country. bing value is not a 2D array or valid serialized query.

I put my Cfc in a Cfc directory at the root.

thanks in advance

cordially

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 17, 2018 Sep 17, 2018

Copy link to clipboard

Copied

Could you please show us your code. You are apparently using a variable called "bing".

For a start, you could just copy the code I have provided.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 18, 2018 Sep 18, 2018

Copy link to clipboard

Copied

Bonjour,

Je n'ai pratiquement pas changé votre code !

Hello,

I have hardly changed your code!

bindfcns.cfc (in Cfc)

<CFINCLUDE template="../admin/inc_init_admin.cfm">

<CFINCLUDE template="../admin/inc_verif_var2.cfm">

<cfcomponent>

<cffunction name="getPays" access="remote" returntype="array">

<cfset var paysQry = "">

<cfset var paysArray = arrayNew(2)>

<cfquery name = "paysQry" dataSource = "#session.dbname#">

SELECT Pays

FROM Monde

WHERE sitename=<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.site#">

ORDER BY pays

</cfquery>

<!--- Values for the first (the default) select option --->

<cfset anneeArray[1][1]="">

<cfset anneeArray[1][2]="Sélectionnez un pays">

<cfloop query="paysQry">

<cfset anneeArray[currentrow+1][1]=paysQry.pays>

<cfset anneeArray[currentrow+1][2]=paysQry.pays>

</cfloop>

<cfreturn paysArray>

</cffunction>

<cffunction name="getVilles" access="remote" returntype="array">

<cfargument name="cePays" required="true" type="string">

<cfset var villesQry = "">

<cfset var villesArray = arrayNew(2)>

<cfquery name = "villesQry" dataSource = "#session.dbname#">

SELECT ville

FROM Monde

WHERE pays = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.cePays#">

ORDER BY ville 

</cfquery>

<!--- Values for the first (the default) select option --->

<cfset villesArray[1][1]="">

<cfset villesArray[1][2]="Sélectionnez une ville">

<cfloop query="villesQry">

<cfset villesArray[currentrow+1][1]=villesQry.ville>

<cfset villesArray[currentrow+1][2]=villesQry.ville>

</cfloop>

<cfreturn villesArray>

</cffunction>

</cfcomponent>

Villes.cfm (in Admin)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<CFINCLUDE template="inc_init_admin.cfm">

<CFINCLUDE template="inc_verif_var2.cfm">

<title>Essai pays/villes</title>

</head>

<body>

<cfform name="villesEtPays">

<cfselect name="pays" bind="../Cfc/bindFcns.getPays()" bindonload="true" />

<br>

<cfselect name="ville" bind="../Cfc/cfc:bindFcns.getVilles({pays})" />

</cfform>

</body>

</html>

Accès : Monde => Num Pays Ville

Merci pour votre aide

Thanks for your help

Marc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2018 Sep 19, 2018

Copy link to clipboard

Copied

marcp12146864  wrote

<cfselect name="pays" bind="../Cfc/bindFcns.getPays()" bindonload="true" />

<br>

<cfselect name="ville" bind="../Cfc/cfc:bindFcns.getVilles({pays})" />

<cfselect name="pays" bind="cfc:Cfc.bindFcns.getPays()" bindonload="true" />

<br>

<cfselect name="ville" bind="cfc:Cfc.bindFcns.getVilles({pays})" />

(cfc: means the bind is to a CFC)

paths:

\admin\Cfc\bindfcns.cfc

\admin\villes.cfm

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 20, 2018 Sep 20, 2018

Copy link to clipboard

Copied

Ce programme est maudit ... et je ne vois plus rien :

This program is cursed ... and I can not see anything:

paths:

\admin\Cfc\bindfcns.cfc

\admin\villes.cfm

Invalid CFML construct found on line 4 at column 1. 

  ColdFusion was looking at the following text:

<

The CFML compiler was processing:

    < marks the beginning of a ColdFusion tag.Did you mean LT or LTE?
  
  The error occurred in \\192.168.0.1\H3637\zennetbuilder.com\Admin\Cfc\bindFcns.cfc: line 4
2 : <CFINCLUDE template="../admin/inc_verif_var2.cfm"> 3 : 4 : <cfcomponent> 

Villes.cfm

<cfform name="villesEtPays">

<cfselect name="pays" bind="cfc:Cfc.bindFcns.getPays()" bindonload="true" />

<br>

<cfselect name="ville" bind="cfc:Cfc.bindFcns.getVilles({pays})" />

</cfform>

Merci encore

thanks again

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2018 Sep 20, 2018

Copy link to clipboard

Copied

It looks like you have some CFML code preceding the opening CFCOMPONENT tag. I don't think this is allowed.

Dave Watts, Fig Leaf Software

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 20, 2018 Sep 20, 2018

Copy link to clipboard

Copied

Mais si je supprime ces includes, je n'ai plus mes informations de session !

But if I delete these includes, I do not have my session information anymore!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2018 Sep 20, 2018

Copy link to clipboard

Copied

Well, you could include a CFINCLUDE within the actual CFCOMPONENT block I think, or within one of the CFFUNCTIONs defined within that component. But in general, I'd say you're doing something wrong if you expect components and functions to be aware of the application state. That's what arguments are for. Functions especially should usually be stateless.

Dave Watts, Fig Leaf Software

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2018 Sep 20, 2018

Copy link to clipboard

Copied

marcp12146864  wrote

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<CFINCLUDE template="inc_init_admin.cfm">

<CFINCLUDE template="inc_verif_var2.cfm">

<title>Essai pays/villes</title>

</head>

Are those headers? If not, then you should put them after between the tags <body> and  </body>

Mais si je supprime ces includes, je n'ai plus mes informations de session !

But if I delete these includes, I do not have my session information anymore!

You should delete the includes from bindfcns.cfc. After all, they are already in the page villes.cfm. That is sufficient to guarantee your session!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2018 Sep 20, 2018

Copy link to clipboard

Copied

I'm pretty sure that all META elements should be placed within the HEAD element, whether they are analogs for headers or not.

Dave Watts, Fig Leaf Software

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 21, 2018 Sep 21, 2018

Copy link to clipboard

Copied

Je pensais qu'étant donné qu'ils étaient dans ville, on n'avait pas besoin de les mettre dans le cfc mais cela ne fonctionne pas !

I thought that since they were in town, we did not need to put them in the cfc but it does not work!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 21, 2018 Sep 21, 2018

Copy link to clipboard

Copied

J'ai essayé de les mettre entre head ou entre body mais j'ai toujours le même message !

I tried to put them between head or body but I always have the same message!

Invalid CFML construct found on line 6 at column 1. 

  ColdFusion was looking at the following text:

<

The CFML compiler was processing:

    < marks the beginning of a ColdFusion tag.Did you mean LT or LTE?
  
  The error occurred in \\192.168.0.1\H3637\zennetbuilder.com\Admin\Cfc\bindFcns.cfc: line 6
4 : </body> 

Mercissss pour votre aide

Mercissss for your help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 21, 2018 Sep 21, 2018

Copy link to clipboard

Copied

I think you misunderstood. Delete the following 2 lines from the file bindFcns.cfc

<CFINCLUDE template="../admin/inc_init_admin.cfm">

<CFINCLUDE template="../admin/inc_verif_var2.cfm">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 22, 2018 Sep 22, 2018

Copy link to clipboard

Copied

Non j'ai bien compris: j'ai enlevé les 2 lignes dans bindFcns.cfc!

Mais j'ai cette erreur !!

No I understood correctly: I removed the 2 lines in bindFcns.cfc!

But I have this error !!

Erreur.gif

Merci

Tank you

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2018 Sep 22, 2018

Copy link to clipboard

Copied

The error occurs because the session variables are undefined. You may or may not be familiar with the application file, Application.cfc. So I shall suggest a solution that does not assume knowledge of it.

Define 2 variables at the beginning of the file bindFcns.cfc, as follows:

<cfcomponent>

<cfset session.dbname="BKBK_DB_name">

<cfset session.site="app.bkbk.com">

<cffunction name="getPays" access="remote" returntype="array">

etc.

Replace the values BKBK_DB_name and app.bkbk.com with your own.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 24, 2018 Sep 24, 2018

Copy link to clipboard

Copied

Ce n'est pas le cas. En effet, lorsque j'affiche les variables, j'ai les bonnes informations

Erreur2.gifJe suis dégoûté! 😞

This is not the case. Indeed, when I display the variables, I have the right information

I'm disgusted! 😞

Tank you

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 24, 2018 Sep 24, 2018

Copy link to clipboard

Copied

Don't worry. We shall get there.

Are you using Application.cfc?

If yes, then you should include the following code in onSessionStart:

<cfset session.dbname="H3637zennet">

<cfset session.site="SoLivres">

If no, then you should create a file called Application.cfc in the directory /Admin/Cfc/. The content of the file is:

<cfcomponent displayname="ApplicationFile" hint="This file runs before every request and initializes your application">

    <cfset this.name = "MesLivres">

    <cfset this.applicationTimeout = "#createTimespan(1,0,0,0)#">

    <cfset this.sessionManagement = "true">

    <cfset this.sessionTimeout = "#createTimeSpan(0,0,20,0)#">

<cffunction name="onApplicationStart" returntype="boolean">

    <cfreturn true>

</cffunction>

<cffunction name="onSessionStart">

    <cfset session.dbname="H3637zennet">

    <cfset session.site="SoLivres">

</cffunction>

</cfcomponent>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2018 Sep 25, 2018

Copy link to clipboard

Copied

Has your original question been answered? If so, mark the correct answer. It will help someone else in future.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 27, 2018 Sep 27, 2018

Copy link to clipboard

Copied

Désespoir ! toujours pas de résultats malgré vos encouragements !

Je ne sais plus où chercher !

Erreur3.gif

Despair! still no results despite your encouragement!

I do not know where to look!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 27, 2018 Sep 27, 2018

Copy link to clipboard

Copied

May I help? I have sent you a private message containing my e-mail address. Zip your files (so as to preserve the directory structure) and mail them to me.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 30, 2018 Sep 30, 2018

Copy link to clipboard

Copied

Could you please give the forum your feedback. Did you apply Application.cfc as suggested?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation