- ColdFusion 9 Developer Tutorial
- John Farrar
- 264字
- 2021-08-05 16:16:40
Improving page flow
The page was refreshed and showed us an update. But it might not be obvious that an update was made. There is also an issue that it does not appear as if the data was updated because we pulled the data object details before the update was made. Also when we saved our edit page data, it would be nice if we were sent back to the list page. Let us take a look at the redirect tag in ColdFusion,<cflocation>
. After an insert or update, the browser will be returned back to the list page. We will also pass a message to the page so that the user will see the updates. First, we will create a message in each of our insert and action code segments. Then, we will push the page back to the list page by passing the message with it:
<cfif structKeyExists(attributes,"submit")> <cfif attributes.id EQ 0> <cfquery datasource="cfb" name="qryInsert"> INSERT INTO product( name , description , price ) VALUES( <cfqueryparam value="#attributes.name#"> , <cfqueryparam value="#attributes.description#"> , <cfqueryparam value="#attributes.price#"> ) </cfquery> <cfset returnMessage = "Your product has been added."> <cfelse> <cfquery datasource="cfb" name="qryUpdate"> UPDATE product SET name = <cfqueryparam value="#attributes. name#"> , description = <cfqueryparam value="#attributes. description#"> , price = <cfqueryparam value="#attributes.price#"> WHERE ID = <cfqueryparam value="#attributes.id#"> </cfquery> <cfset returnMessage = "Your product (#attributes.name#) has been updated."> </cfif> <cflocation url="product_list.cfm?message=#returnMessage#"> </cfif>
You can see that we tacked the message to the end location of our target page. We need to add a<cfparam>
tag to the calling page, so it will be able to handle calls where the URL variable is not available. Then we can add a little section of the page to show the messages, when they exist. Let us edit the product_list.cfm
page as follows:
<!--- Example: product_list.cfm ---> <!--- Processing ---> <cfparam name="url.message" default=""> <cfscript> objProduct = createObject("component","product").init(dsn="cfb"); rsProducts = objProduct.getRecordset(); </cfscript> <!--- Content ---> <cfif url.message NEQ ""> <div> <cfoutput>#url.message#</cfoutput> <hr /> </div> </cfif> <h3>Select a product to edit.</h3> <ul> <cfoutput query="rsProducts"> <li> <a href="product_edit.cfm?id=#rsProducts.id#">#rsProducts.name# </li> </cfoutput> </ul>
This is how the page looks, when we submit our form:

- 商用級AIGC繪畫創(chuàng)作與技巧(Midjourney+Stable Diffusion)
- Python 2.6 Graphics Cookbook
- OpenStack實戰(zhàn)指南
- SolidWorks 2021中文版機械設(shè)計從入門到精通
- Photoshop 平面廣告設(shè)計從入門到精通
- Learning Facebook Application Development
- AI短視頻生成與剪輯實戰(zhàn)108招:ChatGPT+剪映
- 零基礎(chǔ)學(xué)會聲會影2018(全視頻教學(xué)版)
- Midjourney商業(yè)設(shè)計完全教程
- Oracle Fusion Middleware Patterns
- 詳解AutoCAD 2022室內(nèi)設(shè)計(第6版)
- 剪映:從零開始精通短視頻剪輯(電腦版)
- AI繪畫基礎(chǔ)與商業(yè)實戰(zhàn)
- 圖像顯著區(qū)域提取方法及其應(yīng)用研究
- 電磁場數(shù)值計算及基于FreeFEM的編程實現(xiàn)