question about coldfusion displaying query result in a cfgrid - coldfusion

i have a coldfusion cfc and some methods in it. MethodA will return a cfquery object. now i use cfajaxproxy to call MethodA and get the query result in a cfm page. this cfm page already have a cfgrid there. now my question is how can i display the query result getting from MethodA in the grid which already have data display in it?

You should use cfgrid bind="cfc:You.CFC.Path.method(x,y,z,zz)", and you may want to use QueryConvertForGrid() in CF to prepare the data required for cfgrid.
see "Dynamically filling form data" for reference: http://livedocs.adobe.com/coldfusion/8/htmldocs/ajaxui_5.html

Related

How to pass variables to a CFC on Form submission without using hidden fields?

Using: ColdFusion 10, JQuery 1.9, IIS
I made a CFC (allows remote access) which handles the insertion of comments into a database, whether they are new comments or replies to an existing one.
I have a Form which submits to this CFC when you want to make a comment.
At the moment I am passing (as hidden fields) form variables to the CFC to tell it various things about the comment that's to be inserted: e.g. which User the comment is for (the RecipientID) and which CommentID its in reference to (if its a reply). These values change a lot because sometimes a user is replying to another user's comment.
I don't want to send the hidden variables in my form because it can easily be modified by a malicious person. How can I send the main Form information using form variables (e.g. the comment body) but pass the sensitive variables using just ColdFusion so its not manipulable by a hacker?
One thing I could do is submit back to the page itself and then use <cfinvoke> to call the CFC and pass in the arguments. I would set the arguments in the invocation rather than in the Form. Would this be the correct way to do it?
The only place where the malicious users can't modify easily is in the Session.
Keep sensitive stuff in the Session, and make sure the logged in user has the proper right to do the action they requested (e.g. can delete their own stuff only, not other ppl's stuff)
Regarding, "One thing I could do is submit back to the page itself and then use to call the CFC and pass in the arguments. I would set the arguments in the invocation rather than in the Form. Would this be the correct way to do it?"
I think this would be a lot better than submitting to the cfc which is what you say you are doing now. Slight variations of this theme are:
Submit to another page which invokes the cfc method.
Forget the cfc and put the database call into a .cfm page. In
fact, if the cfc contains nothing but the insert query and is not
used elsewhere, it's unnecessary.
As far as not using hidden form fields goes, you might be in trouble. The user info can be stored in the session scope as suggested by Henry, but the recipient info is harder to protect. You could make the recipient id part of the form field name. Then to protect yourself from neer do wells, add another check on the cgi.http_referrer variable.

Where to put DB-accessing template helper functions in Django

So I have a search page with result table. I have a drop down that's a filter from the DB. Instead of calling and populating this drop-down field filter at my view/index() method, can I just call a helper function that returns this list from the DB and populates the drop down at the template level?
I know about context_processors and my understand is that it's for the entire site, but I want this DB call to only happen on this particular page and no where else?
What do call this so I can try to find it in django docs.
Much Thanks
edit: to clarify more: the result table contains movies and drop-down filter is movie types (actions, adventure, thriller, etc). This list is made up from a "SELECT DISTINCT type FROM movies" query.
The Django equivalent of helpers is custom template tags, and it's certainly appropriate to put db-accessing code there.
However, if it's only for a single page, I'm not sure why you wouldn't do it in the view.

Generate pdf in coldfusion with current form inputs

We have a form with a dynamic running totals table beneath the form. For example, when a user changes a value in the Quantity field, the running totals update based on the input (via javascript). The table is displayed only, nothing is saved in the database
We want to be able to generate a pdf that includes the updated running totals. Basically I'm searching if there is some way to pass the current innerHTML within a div to a pdf.
This may have been already asked and answered here- Generate pdf from current document , but the user didn't specifically say that the form updates data after the initial page load. So I just want to be sure I'm not missing something. Thanks. I have a feeling I should look into localStorage for this.
(From the comments)
I think you may be over-complicating the PDF functionality. It is not necessary to keep up with the local changes that the users make as far as generating a PDF is concerned. Most likely the users will make whatever changes to the page and then click a link/button to generate a PDF only after completing all of the changes. At that point you could simply submit a form with all of the updated values to ColdFusion and generate your PDF file. Instead of/or in conjunction with updating the innerHTML of a div, update the hidden form fields as well. Then on the ColdFusion server you could use something like the CFDocument tag to create your PDF from the form fields that were submitted. (Remember to validate all of the form field data before using it.)

Prevent duplicate update of CFgrid

I have a CFgrid with selectMode="Edit". Again I have an update method binded to the cfgrid via my cfc. However I am ble to update the grid with duplicate values. I can prevent the db from updating by chking for existing record but I wanted to let the user be thrown with a message that his update was not succesful. In this case he will only know of his update not being succesfull only after he has refreshed the page only to find the old value still exist.
I wanted to know if there is any event within the cfgrid which I can trigger to show the user that his update is trying duplicate the data and cannot be completed.
You haven't posted any code, but I am guessing you are using an HTML grid with the onChange attribute to trigger the edit? If that is the case, then you can also use the onError attribute and then just have your CFC throw an error if the data is not satisfactory with cfthrow. Then in your onError handler, you can handle the error as you please. You can find more information about working with HTML grids in CF9 here

passing and getting variables to a cfwindow

I have a table within a form that has many identical rows. At the beginning of each row is a text field and a button that creates a <cfwindow> so that the user can browse an inventory and select a single item. Then I need that item's name and ID to get sent back to the main page and populate the text box.
The main page form works fine. The <cfwindow> works fine (search, display, etc..). I cannot figure out a way to get the variable being set in the <cfwindow> back to the main page and just populate the text field for that specific row and not redraw the entire page. I can't even get the <cfwindow> to access any variable on the main page and I thought that it was just a floating div and would have access to all of the main page variables that are set.
This is one row of the main page (the index is for looping through to create unique names for each row variables):
<cfinput type="button" value="Select" name="xSelect#i#" onClick="ColdFusion.Window.create(blah blah blah...)/>.
<cfinput type="text" name="x1s#i#xName" value="form.x1s#i#xName" size="30" disabled="true"/>
in the <cfwindow>, a query populates a list of items, each with a radio button. User needs to select one and it needs to return that item's ID back to the main page for that row:
I appreciate the feedback. Here's what I ended up doing:
- passed the variables to the cfwindow via url with a button and an onClick="ColdFusion.Window.create..."
- in the cfwindow, I used the url variables as a reference and I have a search dialogue that then sends the search results along with the url variable (via url variables) to a simple action page that just displays a form with the variables populated via an onclick="javascript:ColdFusion.navigate..."
- back in the main page I have a cfdiv that binds to the action page via a url
So by starting with a reference that I pass to my search function, I keep it "tagged" and then every time it is refreshed it shows up in the main page correctly.
So it's working now and the last thing that I need to do is put all my dynamic variables in an array to reduce the overhead.
In ColdFusion you could put something into the session scope or you could use javascript to set hidden fields on the calling page. There may be a nicer solution but that's a couple of quick ones.
Use a Javascript function call in your link on the parent window.
From the Javascript function, use ColdFusion.Window.create to create the child window with a dynamic url passing the vars you need.
Et voilĂ .