As a simple example of the problem:
<cfsavecontent variable = "pageOutput">
<cfoutput>
<!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>
<title>#page_title#</title>
</head>
<body>
<cfdump var="#URL#">
</body>
</html>
</cfoutput>
</cfsavecontent>
I save this page to disk. Then when I call this newly-generated page via the following URL:
http://blah/products.cfm?search_keyword=bathroom&search_category=451&search_province=Auckland
The dump doesn't display the newly-passed url vars.
I'm obviously missing something pretty basic here.
What you need to do is replace the opening or closing portion of the tag so that when it gets output you have a valid tag. Something like this:
<cfsavecontent variable="page">
<cfset sCfO = "<" >
<cfset sCfC = "</" >
<!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>
<title><cfoutput>#page_title#</cfoutput></title>
</head>
<body>
<cfoutput>#sCFO#</cfoutput>cfdump var="#URL#">
<cfoutput>#sCFO#</cfoutput>cfoutput>
#URL.myMessage#
<cfoutput>#sCFC#</cfoutput>cfoutput>
</body>
</html>
Hopefully that makes sense...
If I understand your explanations correctly, in your generated with cfsavecontent pagevariables are already substituted, so you have the static HTML in products.cfm. Try to open it in editor and review the code.
I have a question: what is the purpose of using cfsavecontent here? What are you trying to achieve? Looks like you may not need it at all, plain ol' CFML should do the job.
I would be more inclined to hide that in a function which would read much nicer in your example you could call dumpVariable(url) and encapsulate that in a function. We actually had to do something similar by parsing custom tags from a database into a render function that used cfmodule for the actual implementation. I was pretty happy with the results and it was much easier to tell what was going on in the code than arbitrary character replacement.
Related
I am at learning stage in ColdFusion. Now I am trying to execute below code to display variable content by using <cfset> and <cfoutput> tags. I completed my server installation and I am able to login to server with admin credentials. But it executed as normal html page, not getting the result from ColdFusion tags.
Do I need to install anything apart from this?
<!DOCTYPE html>
<html>
body>
<body background="download.jpg">
<cfset name ="swanav"/>
<cfoutput>#name#</cfoutput>
</body>
</html>
A small correction to your code,
<!DOCTYPE html>
<html>
<body background="download.jpg">
<cfset name="swanav" />
<cfoutput>#name#</cfoutput>
</body>
</html>
The code needs to be placed in,
/cfusion/wwwroot
I encountered the following problem in our application: After each server restart or redeployment of the application the first attempt to navigate to one specific page will fail with an exception:
javax.faces.view.facelets.TagException: /testing/target.xhtml #8,72 <ofc:testComp> Tag Library supports namespace: http://java.sun.com/jsf/composite/of-components, but no tag was defined for name: testComp
I laboured a while to strip this down to a minimal version. In doing so I figured out the following:
The problem occurs when:
The server has been restarted or the application redeployed
One tries to navigate to a certain page through an h:commandLink
The target page uses a composite component
The problem goes away when:
one reaches the target page in some other way, e.g. through an h:outputLink or via URL
ever after the target page has been successfully reached once
I ruled out all kinds of things (we're on Mojarra 2.1.7 and the target page does not nest components, so it's not this problem with nested namespace declarations) and narrowed it down to the following "culprit":
The source page uses a template, which I simplified as follows:
<!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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Testpage</title>
</h:head>
<h:body>
<h:form id="form">
<ui:insert name="content"/>
<ui:include src="some_other_content.xhtml" />
</h:form>
</h:body>
</html>
If I remove the ui:include everything works. Can somebody explain to me what is happening here? It seems to have something to do with initializing my component library after a server restart, but I don't get how the include in the template has to do with it. As far as I know this is the standard way to include some fixed content to a page? If this is not how it should be done, please let me know what other ways there are.
Thanks!
Remaining code snippets for completeness (no magic happening here):
source_page.xhtml
<ui:composition template="/testing/test_template.xhtml">
<ui:define name="content">
<h:outputLink value="target.xhtml">Outputlink to target</h:outputLink> <br />
<h:commandLink value="Commandlink to target" action="target.xhtml" />
</ui:define>
</ui:composition>
target.xhtml
<!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"
xmlns:ofc="http://java.sun.com/jsf/composite/of-components"
xmlns:h="http://java.sun.com/jsf/html">
<h:head></h:head>
<h:body>
<ofc:testComp content="This is a component for testing purposes" />
</h:body>
</html>
testComp.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface>
<cc:attribute name="content" required="true" />
</cc:interface>
<cc:implementation>
<h:outputText value="#{cc.attrs.content}" />
</cc:implementation>
</html>
And finally, some_other_content.xhtml is just a random Hello-World-Page.
It took quite some time, but we finally managed to upgrade. We are now running Mojarra 2.1.21.
I re-enabled the include and tried to restore the original setup as best as I could. I did not get any errors. The code has changed in other places too, so I can't say with absolute certainty that this was the sole reason it works. However, the original problem was quite reproducible and the general setup is basically the same as before, so I'm pretty sure one of those many skipped Mojarra versions did the trick.
The project I have is to create a Vista Print like application. I have created a very basic interface that places a resizable div in an area that can be dragged around. I am also able to place text into this div via pop-up iframe with designmode. I then write this to a database.
I then call this data and create a pdf using Coldfusions cfdocument.
The issue is when the PDF is created the font looks slightly thicker and the word wrap is different than the html page interface which is very important. Note: The word wraps are determined by the divs height and width. It looks fine on the cfdocument process page it is just off when the pdf is created. Anyone have any ideas on this or can point me to some info that could help?
Thanks in advance.
Code Here:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<cfset webRes = "96">
<cfset pxlWidth = "921">
<cfset pxlHeight = "1178">
<cfset inWidth = (pxlWidth/webres)>
<cfset inHeight = (pxlHeight/webres)>
<cfquery name="qTextData" datasource="ds">
SELECT DocID, TextID, Width, Height, PosX, PosY, FontFamily, FontColor, FontSize, TextValue
FROM TextEditor
WHERE ((DocID = #session.docid#))
</cfquery>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Create PDF</title>
</head>
<cfoutput>
<cfdocument filename="mypdf.pdf" name="mypdf" fontembed="yes" format="pdf" overwrite="yes" pageheight="#inHeight#" pagewidth="#inWidth#" pagetype="custom">
<cfdocumentsection margintop="0" marginright="0" marginbottom="0" marginleft="0">
<body align="center" marginheight="0" marginwidth="0">
<div id="pageContainer" style="background-image:url(resources/image.caspx.jpg); background-repeat:no-repeat; height:#pxlHeight#px; width:#pxlWidth#px;">
<cfloop query="qTextData">
<div id="divTextField_#TextID#" style="position:absolute; top:#PosY#px; left:#PosX#px; width:#width#px; height:#Height#px; color:#FontColor#; font-family:#FontFamily#; font-size:#FontSize#pt; vertical-align:text-top; line-spacing:normal;">
#TextValue#
</div>
</cfloop>
</div>
</body>
</cfdocumentsection>
</cfdocument>
</cfoutput>
<script type="text/javascript">
window.open('http://linktopdf/mypdf.pdf','newWin','resizable=1');
</script>
</html>
I tried making this a comment but I started getting long winded and it was too large so it may not be the "answer" but if nothing else I'm sure it will have some helpful information in it.
What % are you viewing at and have you tried printing it out?
I've noticed that things can look lopsided or bigger than usual because they are just rendered weird in acrobat (or your PDF viewer of choice). Try adjusting the zoom and see if the display changes, also see if it prints correctly.
I have also found that like James suggested, I need special css just for the document. The CSS could be as odd as making one side of the div have a 1px larger border to make it look correct. Also keep in mind that although you view PDFs on the screen it is still a "print" media. PT means 1/72 of an inch which will look bigger when you scale from your 19+ inch monitor (which is further effected by your pixel resolution) to an 8.5" x 11" piece of paper that doesn't truly know what a pixel is. You may need to try adjusting your font size on the fly, something like: font-size: #fontSize-2#pt;. Change -2 to anything that may work for your output. You could also try using a unit that scales, like em.
The cfdocument docs list all the CSS that is supported as well as identify some restrictions. It does not appear that line-spacing:normal; is supported. Also make sure all your CSS is included inline or in a style tag but avoid using a linked .css file. I see you're doing that, just adding tips and pointers.
Also, according to the docs:
ColdFusion does not return HTML and CFML outside of
the <cfdocument></cfdocument> pair.
That means ColdFusion is processing your cfset statements but it does not return
<!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=utf-8" />
<title>Create PDF</title>
</head>
and
<script type="text/javascript">
window.open('http://linktopdf/mypdf.pdf','newWin','resizable=1');
</script>
</html>
So it is possible that iText isn't rendering it as you would expect because
It does not have a doctype
It is an ill-formed HTML document
I was trying to run this code, and browser ask me to download pdf file which is good, But it was not loading remaining HTML code or you can say I could not see "Thank you Message".
Am I doing something wrong or missing something?
Need your help
<cfheader name="content-disposition" value="attachment; filename=134.pdf"/>
<cfcontent type="application/pdf" file="#ExpandPath( './134.pdf' )#"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Download Now</title>
</head>
Thank you for your interest in downloading
this file. Your download should begin shortly.
Maybe show the 'download will begin shortly' message first as a distinct page, which then redirects (JavaScript or meta tag...) to the .cfm that generates the PDF.
What you're trying to do is load the PDF file immediatly. As stated before you should have a basic HTML Page:
<html>
<head>
<meta http-equiv="refresh" content="2;url=getpdf.cfm?file=123.pdf">
..rest of head
</head>
<body>
Download will begin shortly.
</body>
</html>
This getpdf.cfm?file=123.pdf will be
<cfheader name="content-disposition" value="attachment; filename=134.pdf"/>
<cfcontent type="application/pdf" file="#ExpandPath( './134.pdf' )#"/>
The reason it wont work, is that you browser reads the "headers" and will basically see the file as a PDF file. Like you were downloading a ".pdf". Now you're putting one step in between and let the browser redirect to the PDF download.
I'm trying to understand ColdFusion, as I am coming from ASP.NET. I've put together a sample page to piggy-back off some already finished code -- but I can't seem to get the actual data from the object I am creating:
<cfset objProduct = createObject("component", "com.MyObj.Product")>
<cfset prodExists = objProduct.getProduct(10)>
<html>
<head/>
<body>
<h2>#objProduct.ProductName#</h2>
</body>
... It simply prints the literal #objProduct.ProductName# text, and not the data from within the object. Any idea where I'm going astray?
Thanks!
Don't forget the <cfoutput>!
<cfoutput>
<html>
<head>
<title>Test</title>
</head>
<body>
<h2>#HtmlEditFormat(objProduct.ProductName)#</h2>
</body>
</html>
</cfoutput>
You forgot the CFOUTPUT tags.
You're trying to output the wrong variable.
#objProduct.getProduct(10)#
or
<cfoutput>#prodExists#</cfoutput>