Using facebook4j and to post a link you must create and supply a URL object. However when I try to do so I get a class not found error. Appears CF10 is running on JRE 7.0.15
For example this throws an error
<cfset testurl = createObject("java", "java.lang.URL").init("http://www.google.com") />
but this doesn't for a string object
<cfset testurl = createObject("java", "java.lang.String").init("http://www.google.com") />
Any suggestions would be appreciated.
Right after posting of course I find some old documentation mentioning the class name is java.net.URL
Related
I recently started learning coldfusion. I am getting a bit confused, reading through numerous websites regarding the function cfhttp.filecontent.
Can any of you help me understand and provide me with an example of how I would format the following code I am writing? I am already grabbing name and email from a form on the index page and trying to initiate an API request and get the password back, formatted correctly.
<cfset passwordcomplexity = 4>
<cfinclude template='header.cfm'>
<cfhttp method="GET" url="https://hardest.pw/api/#passwordlenght#/#passwordcomplexity#">
<cfset returnString = cfhttp.filecontent>
<cfdump var="#returnString#">
<!---<cfmail to="#form.email#"
from="no-reply#training-pavel.com"
subject="New random password"
type="text">
Hey there, #form.name#!
We've just generated a new password for you! You can see it below:
</cfmail>--->
<cfinclude template='footer.cfm'>
At the end I just get something like this:
{"code":200,"desc":"Command completed successfully","password":"[&Vo4%T#l8","hardestlink":"https:\/\/hardest.pw\/0758828a-a6f6-4f9b-9bd7-c0dc778de0b7"}
I've never seen this before I have a component in a cfc file and I use
<cfset request = CreateObject("component","path/to/component") />
When I set request to the above or:
<cfset request = CreateObject("component","path/to/component").init() /> or
<cfset request = CreateObject("component","path/to/component").from_request() />
etc I always get a struct with a single item that is the equivilant of
{cfdumpinited = false}
I've never see this before. The from_request method reuturns init and init returns this.
When I <cfdump this> right before the <cfreturn this> I get the full object output on the screen. But when I <cfdump request> I get the struct stated above. Anyone know what causes Coldfusion to return this type of struct. I can post the entire cfc but I don't think that will help as I stated, right before the return I can output this and it is the entire object/component.
request is a scope in ColdFusion, therefore you should use another variable name.
Assuming the following code in a regular .cfm file, not a CFC:
<cffunction name="myFunction">
<cfobject type="java" action="create" class="path.to.my.java.class" name="myJavaVariable">
</cffunction>
What is going to be the scope of the created object? I'm getting the feeling it's not limited to the function scope. If so, how to make it local? Would the following work?
<cfset var myJavaVariable = "">
<cfobject ... name="myJavaVariable">
EDIT:
I forgot to say I was under Coldfusion MX 7, as it does prevent some useful solutions found on the web from working.
I did find a workaround where one creates a fake local scope (<cfset var local = StructNew()>). It does work well even for such tags since you can put the return variable as local.someVar.
I'd question why you're using <cfobject> at all, rather than the more obvious simple assignment:
var myJavaVariable = createObject("java", "path.to.my.java.class");
Isn't that more natural code anyhow?
I am working on a plugin that handles some more advanced searching of site members and in looking at the Advanced Search for the Site Members (cpublicusers.dsp_advancedsearch.cfm) I found that the way it does the pagination is that it sets the search form to the session. I tried to do the following using this code:
<cfif NOT structKeyExists(SESSION,'reportForm')>
<cfset SESSION.reportForm = FORM />
<cfset sessionisset = true />
<cfelse>
<cfset sessionisset = false />
The sessionisset variable is just for my testing.
When I try to navigate to the pagination I am finding that the session.reportForm variable is being cleared. Can anyone explain why this would be.
FORM is a system structure that's re-initialized on each page. Structures are passed "by reference" meaning you're just storing a pointer to FORM. So when FORM is reinitialized - so is your session variable.
The fix is to make a deep copy of the structure so it's not affected by changes to FORM.
view sourceprint?
<cfset SESSION.reportForm = duplicate(FORM) />
After trying for about an hour without success... (coldfusion8) a dummy question, but I*m stuck:
My URL (Jquery Mobile, no pushstate, that's why it looks like it is):
http://www.page.de/test/mem/search.cfm#/test/mem/search.cfm?id=9900000003869
If I output:
<cfdump output="e:\website\dump.txt" label="catch" var="#url#">
I get this:
catch - struct
ID: 9900000003869
But how do i access it... I'm trying forever, nothing works:
<cfdump output="e:\website\dump.txt" label="catch" var="#id#">
<cfdump output="e:\website\dump.txt" label="catch" var="#ID#">
<cfdump output="e:\website\dump.txt" label="catch" var="#url.id#">
<cfdump output="e:\website\dump.txt" label="catch" var="#url.ID#">
<cfdump output="e:\website\dump.txt" label="catch" var="#StructGetValue(url,"id")d#">
...
Thanks for helping!
Ok... This works:
URL = http://www.page.de/test/mem/search.cfm#/test/mem/search.cfm?id=9900000003869
<cfset objRequest = GetPageContext().GetRequest() />
<cfset strUrl = right( objRequest.GetRequestUrl().Append( "?" & objRequest.GetQueryString() ).ToString(), 13)>
Credit
If someone finds an easier, please post. I will check as answer.
You're trying to read this from a txt file?
Can you not simply use:
<cfdump label="catch" var="#url.id#" />
Does that work?
EDIT:
Could you try capturing and formatting what you need first then after, writing it to the file?
For example, try using:
<cfsavecontent variable="myFileContents">
<cfoutput>#url.id#</cfoutput>
</cfsavecontent>
<cffile action="Write" file="e:\website\dump.txt" output="#myFileContents#" />
I have not tested this code, but give it a go and see!
Might want to put a check on that URL variable too using isDefined()
Good luck.
Doing some research on fragment identifiers (which is a new term to me :( )prompted by Peter and Duncan's comments, I've found from wiki: http://en.wikipedia.org/wiki/Fragment_identifier
The fragment identifier functions differently than the rest of the
URI: namely, its processing is exclusively client-side with no
participation from the server — of course the server typically helps
to determine the MIME type, and the MIME type determines the
processing of fragments. When an agent (such as a Web browser)
requests a resource from a Web server, the agent sends the URI to
the server, but does not send the fragment. Instead, the agent waits
for the server to send the resource, and then the agent processes the
resource according to the document type and fragment value.
now, being your client IS sending the fragment and the url variable is accessible to you for some reason, using it is done by my original post to follow.
<cfoutput>
is generally how you output a variable or other evaluations to the screen.
<cfset myName = "Travis">
<cfoutput>Hello, my name is #myName#</cfoutput>
You can also access the variable by using it in a statement that doesn't output anywhere.
<cfset myFullName = myName & " Mak">
You can also use the variables in a query
<cfquery name = "qSomeQuery" datasource = "#application.dsn#">
select * from table where id = #url.id#
</cfquery>
However, that's the bad way to use it in a query, you should always use cfquery param.
<cfquery name = "qSomeQuery" datasource = "#application.dsn#">
select * from table where id = <cfqueryparam cfsqltype="cf_sql_integer" value="#url.id#">
</cfquery>
The problem you're having in testing the variable is due to incorrect syntax.
<cfif isDefined("url.id")> verses <cfif isDefined(url.id)> a more accurate test is <cfif structKeyExists(url, "id")>
For some reason my CF server truncates everything in the url after the # but yours doesn't seem to have this problem. As your cfdump states, you can see your url variables so "accessing" the url variable is as easy as using it: #url.id# or testing it <cfif isDefined("url.id")>