Re: [framework-one] DAO/cfm issue

48 views
Skip to first unread message

Jim Priest

unread,
Apr 12, 2013, 9:28:03 AM4/12/13
to framew...@googlegroups.com
Which one of these are you working on - and is failing?

1. lists all the "brands" in a sql table
2. edit current brand entries
3. create new brand entries that are saved away to the table.
(currently doing, not complete)

Jim

Matt Quackenbush

unread,
Apr 12, 2013, 9:28:43 AM4/12/13
to framew...@googlegroups.com
At a quick glance ...

  1. Your DAO's updateBrands() method does not require the arguments to be passed; it should.
  2. Your main controller's getBrands() method is calling getBrandsService().updateBrands() and getBrandsService().createBrands(), each without providing any arguments; it should not. Rather, it should *only* be calling getBrandsService().getBrands() since you're merely trying to output the list of brands.

Fix those problems first and see how it goes.

HTH




On Fri, Apr 12, 2013 at 9:15 AM, <caroline.e...@lovehoney.co.uk> wrote:
Hello,
I am new to FW/1 and I am trying to set up a new tool that allows the user to do three things:
1. lists all the "brands" in a sql table
2. edit current brand entries
3. create new brand entries that are saved away to the table. (currently doing, not complete)

I have three view pages at the moment (default.cfm (lists the brands), edit.cfm (allows you to edit the brands) and error.cfm).
My cfc in the DAO section is:
<cfcomponent output="true" hint="the DAO cfc that gets all the brands in the given table.">

<cffunction name="getBrands" returntype="query" access="public">
<cfquery datasource="tester" name="local.qry">
SELECT BrandName AS brandName
,Slug AS slug
,BrandId AS brandId
FROM tblBrand
ORDER BY brandId
</cfquery>
<!--- <cfdump var="#local.qry#"
abort="true" /> --->
<cfreturn local.qry />
</cffunction>

<cffunction name="updateBrands" returntype="boolean" access="public">
<cfargument name="brandName" type="string" required="false">
<cfargument name="slug" type="string" required="false">
<cfargument name="brandId" type="int" required="true">
<cfquery datasource="tester" name="local.qry">
UPDATE tblBrand
SET BrandName=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.brandName#" />
,Slug=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.slug#" />
WHERE BrandId=<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.brandId#" />
SELECT @@ROWCOUNT AS rows_affected
</cfquery>
<cfreturn local.qry.rows_affected gt 0 />
</cffunction>
</cfcomponent>

and the controllers/main.cfc is:
component output="false" accessors="true"
{ property name="brandsService";
public void function default (required any rc)
{ rc.qBrands = getBrandsService().getBrands();
rc.uBrands = getBrandsService().updateBrands();
rc.cBrands = getBrandsService().createBrands();
}
}

and the model/service is:
component output="false" accessors="true"  {
property name="brandsDAO";
public query function getBrands ()
{ var qry = getBrandsDAO().getBrands();
return qry;
}
public boolean function updateBrands (brandName,brandId,slug)
{ var qry = getBrandsDAO().updateBrands(brandName,brandId,slug);
return qry;
}
}

This doesn't work and I don't understand why.. the error says: variable [BRANDNAME] doesn't exist
But the brand name has be to passed in via the cfm page... Help me please!!
Thanks,
Caroline

--
--
FW/1 on RIAForge: http://fw1.riaforge.org/
 
FW/1 on github: http://github.com/seancorfield/fw1
 
FW/1 on Google Groups: http://groups.google.com/group/framework-one
 
---
You received this message because you are subscribed to the Google Groups "framework-one" group.
To unsubscribe from this group and stop receiving emails from it, send an email to framework-on...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

caroline.e...@lovehoney.co.uk

unread,
Apr 12, 2013, 9:38:50 AM4/12/13
to framew...@googlegroups.com
Awesome, that fixed that error but now I'm getting a new error :(
On my edit.cfm page I have this:
<cfif StructKeyexists(form, 'Submit') AND value="Update">
<cfset local.update = rc.uBrands />
<cfif local.update = True>
<cfset session.pagemessages.add("confirm","Brand updated successfully.") />
<cfcontent reset="true" />
<cflocation URL="/default.cfm" addtoken="false" statuscode="301" />
<cfelse>
<!--- Warning--->
<cfset session.pagemessages.add("warning","Something went wrong..") />
<cfcontent reset="true" />
<cflocation URL="/error.cfm" addtoken="false" statuscode="301" />
</cfif>
</cfif>

<cfoutput>
<p><a href="<cfoutput>#buildUrl('main.default')#</cfoutput>">Go back</a></p>
<h2>Edit brand</h2>
<body>
<td>Brand name: <input type="text" name="newBrandName" width="10"></td>
</br>
<td>Slug: <input type="text" name="newSlug" width="10"></td>
</br>
<td><form action="default.cfm" method="post">
<input type="submit" name="submit" class="button" value="Update" /></form></td>
</body>
</cfoutput>

The top part handling what to do and what to call when update is called. I'm not sure if this is allowed using FW/1 but it's returning this error..
invalid assignment left-hand side (railo.transformer.bytecode.op.OpBool)

caroline.e...@lovehoney.co.uk

unread,
Apr 12, 2013, 9:39:33 AM4/12/13
to framew...@googlegroups.com
editing the current bran entries is what I am stuck on at the moment, I've only built the back-end functions for the create new brand entries..

Matt Quackenbush

unread,
Apr 12, 2013, 9:42:12 AM4/12/13
to framew...@googlegroups.com
On Fri, Apr 12, 2013 at 9:38 AM, <caroline.e...@lovehoney.co.uk> wrote:
<cfif StructKeyexists(form, 'Submit') AND value="Update">

The top part handling what to do and what to call when update is called. I'm not sure if this is allowed using FW/1 but it's returning this error..
invalid assignment left-hand side (railo.transformer.bytecode.op.OpBool)



A single = is an assignment operator. You're trying to compare, so you need double ==.

caroline.e...@lovehoney.co.uk

unread,
Apr 12, 2013, 9:50:11 AM4/12/13
to framew...@googlegroups.com
Of course.. I missed that one :/
How would I now reference back to the updateBrand function in my dao/brands.cfc file?

Matt Quackenbush

unread,
Apr 12, 2013, 10:01:44 AM4/12/13
to framew...@googlegroups.com
I'm not following the question. Can you elaborate, including showing code you've tried and stacktrace for any exceptions encountered?


--

caroline.e...@lovehoney.co.uk

unread,
Apr 12, 2013, 10:10:22 AM4/12/13
to framew...@googlegroups.com
When I click on the "Update" button on the edit.cfm page, how would I reference my UpdateBrands function in my dao/brands.cfc:
<cffunction name="updateBrands" returntype="boolean" access="public">
<cfargument name="newBrandName" type="string" required="true">
<cfargument name="newSlug" type="string" required="true">
<cfargument name="brandId" type="int" required="true">
<cfquery datasource="tester" name="local.qry">
UPDATE tblBrand
SET BrandName=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.brandName#" />
,Slug=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.slug#" />
WHERE BrandId=<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.brandId#" />
SELECT @@ROWCOUNT AS rows_affected
</cfquery>
<cfreturn local.qry.rows_affected gt 0 />
</cffunction>

It is set in my service/brands.cfc as...
public boolean function updateBrands (brandName,brandId,slug)
{
var qry = getBrandsDAO().updateBrands(brandName,brandId,slug);
return qry;
}
 but how do I reference back to that so the cfm knows to call and pass items through.
My edit page looks like this now.. 
 <cfif StructKeyexists(form, 'Submit')>
<cfset local.update = rc.uBrands(newBrandName=form.newBrandName, newSlug=form.newSlug, brandId=rc.qBrands.brandId) />
<cfif local.update = True>
<cfset session.pagemessages.add("confirm","Brand updated successfully.") />
<cfcontent reset="true" />
<cflocation URL="<cfoutput>#buildUrl('main.edit')#</cfoutput>" addtoken="false" statuscode="301" />
<cfelse>
<!--- Warning--->
<cfset session.pagemessages.add("warning","Something went wrong..") />
<cfcontent reset="true" />
<cflocation URL="<cfoutput>#buildUrl('main.error')#</cfoutput>" addtoken="false" statuscode="301" />
</cfif>
</cfif>

<cfoutput>
<p><a href="<cfoutput>#buildUrl('main.default')#</cfoutput>">Go back</a></p>
<h2>Edit brand</h2>
<body>
<td>Brand name: <input type="text" name="newBrandName" width="10"></td>
</br>
<td>Slug: <input type="text" name="newSlug" width="10"></td>
</br>
<td><form action="<cfoutput>#buildUrl('main.edit')#</cfoutput>" method="post">
<input type="submit" name="submit" class="button" value="Update" /></form></td>
</body>
</cfoutput>


Louis

unread,
Apr 12, 2013, 10:17:38 AM4/12/13
to framew...@googlegroups.com
Whoah there! What's going on with your HTML? You've got table cells that aren't within a <table> and a <body> tag that is after an <h2> and a <p>, why's that? 

Also, your form isn't going to submit the newBrandName and newSlug fields as they aren't within the <form> tag...

<html>
<head>
</head>
<body>
<cfoutput>
<p><a href="<cfoutput>#buildUrl('main.default')#</cfoutput>">Go back</a></p>
<h2>Edit brand</h2>
<form action="<cfoutput>#buildUrl('main.edit')#</cfoutput>" method="post">
<table>
<tr>
<td>Brand name: <input type="text" name="newBrandName" width="10"></td>
</tr>
<tr>
<td>Slug: <input type="text" name="newSlug" width="10"></td>
</tr>
<tr>
<td><input type="submit" name="submit" class="button" value="Update" /></td>
</tr>
</table>
</form>
</cfoutput>

</body>
</html>

Matt Quackenbush

unread,
Apr 12, 2013, 10:18:18 AM4/12/13
to framew...@googlegroups.com
Based upon the code you've shown here, I think you have a fundamental misunderstanding of MVC, which is what FW/1 is all about. I don't have a link handy at the moment, but there was recently a thread with a bunch of tutorials linked. I would highly recommend you search for that thread and read up on "getting started" type tutorials.

In a nutshell, your view doesn't handle anything except for displaying items to the screen.

Seth Johnson

unread,
Apr 12, 2013, 10:44:57 AM4/12/13
to framew...@googlegroups.com
In short, you will handle the update and insert logic in the controller and then redirect to the appropriate view.  The display files should not touch your services, this should instead happen in a method in your controller.  Your form will post to a processing method, the process method will perform your update or insert and then redirect to a view.  If the action was successful you may decide to redirect back to a master list, if unsuccessful you will typically redirect back to the form and communicate with the user what was wrong.

Seth

caroline.e...@lovehoney.co.uk

unread,
Apr 12, 2013, 10:49:44 AM4/12/13
to framew...@googlegroups.com
Oh.. I don't understand how one view can call a controller to handle all of it's functions..
Like the default.cfm links to the Edit page but needs to also only show up that particular brand.. I can't keep passing around Ids, surely?

Seth Johnson

unread,
Apr 12, 2013, 10:54:54 AM4/12/13
to framew...@googlegroups.com
Surely you do need to pass around the id's, luckily fw/1 puts all form and url variables into the rc scope for you.  It sounds like you are already heading in the right direction by separating out your services and dao's.  Now you are separating the views from the logic and leaving it up to the controller to decide the application's flow. 

Seth

Reply all
Reply to author
Forward
0 new messages