The Coldfusion Open Source Forums
Home | ImageCFC | CFFM | BlogCFM | CFMBB | CFOpenMail / ImapCFC | CFOpenChat
Forums | Profile | Inbox | Members | Chat | Search | Login | RSS
Vivio Technologies CFML Hosting
New Topic Reply Subscription Options   Previous Page  Page: 1   Previous Page

Forums: CFFM: Weird behavior with Rialo
Created on: 10/18/08 {ts '2013-05-25 20:45:00'} Views: 9811 Replies: 7
Weird behavior with Rialo
Posted Saturday, October 18, 2008 at {ts '2013-05-25 20:45:00'}

Hey Rick.
I ran into a weird bug with Railo on CFFM

javaRB.cfc is not loading up the msg struct for some weird reason. I thought you might be able to figure it out due to your immersion in the project.

I outputted the values that should be loaded and did a dump of the struct and all looks like it should.

Dump/error/values
http://www.myinternetisbroken.com/misc/index.cfm.htm

My code for dumpetc
http://mgt.pastebin.com/f2e8d24d2

but when a msg is called directly
"cffm.resourceKit.Msg.t1"

railo complains about:
"key [MSG] doesn't exist in struc"

even though it looks like those values are getting loaded and they are in the cfdump.

Any Ideas?

Great stuff BTW... folks love CFMM.

RE: Weird behavior with Rialo
Posted Monday, October 20, 2008 at {ts '2013-05-25 22:16:00'}

Had the same problem Gerald, much googling showed that the issue was with how CF handles structs versus Railo.

what you need to do (unfortunately) is go through the CFFM files and find all the msg and button text references and swap this.that.msg.t34 for this.that["msg.t34"]

It's really painful. Sadly it looks like a lot of people have already done it, but nobody has posted updated files anywhere. I'd send you the ones we did, but we've made extensive changes to our copy to incorporate user/folder restrictions.

RE: Weird behavior with Rialo
Posted Monday, October 20, 2008 at {ts '2013-05-25 22:27:00'}

Np. Thanx Rick

Fortunately:
http://xkcd.com/208/

RE: Weird behavior with Rialo
Posted Monday, October 20, 2008 at {ts '2013-05-25 22:47:00'}

yup regex is the easiest way to fix it.. just dont forget you dont need to fix all the cffm_xxx.cfm files.. just fix cffm.cfm and save it over the top of cffm_file.cfm, cffm_image.cfm etc

just asked one of our devs to paste the regex he used to sort this in here for you.. hopefully he wont be too long

RE: Weird behavior with Rialo
Posted Monday, October 20, 2008 at {ts '2013-05-25 23:09:00'}

Hi,

Didnt have time to bundle it into an executeable so heres the java code for now, nothing special and it can probably be adapted for other purposes or embedded in a CF function, all the following does is read the file in and update the structs as it goes then prints the output to screen so u will need to load your cffm pages into a text file and then copy your output back into your cffm files, i plan to adapt it to process multi files and output the results directly to file but not sure when i will get a chance.


import java.io.File;
import java.util.Scanner;
import java.util.regex.*;

public class Replacement {
public static void main(String[] args)
throws Exception {

    Pattern p = Pattern.compile("(\\w*)\\.(\\w*)\\.(\\w*)\\.(\\w*)");
   
    File tempFile = new File("test.txt");
      Scanner reader = new Scanner(tempFile);
      
      
   
      while(reader.hasNext()){
            
   
// Create a matcher with an input string
Matcher m = p.matcher(reader.nextLine());
StringBuffer sb = new StringBuffer();
boolean result = m.find();
// Loop through and create a new String
// with the replacements
// System.out.println(m.group());
while(result) {
   String[] pieces = m.group().split("\\.");
   
   String temp1 ="";
   String temp2 ="";
   if(pieces.length == 4){
   
      temp2 = pieces[pieces.length - 2] + "." + pieces[pieces.length - 1];
      
      for(int i = 0; i <= pieces.length - 3; i++){
      if(temp1 != ""){
         temp1 = temp1 + "." + pieces[i];
      } else {
         temp1 = pieces[i];
      }
         
      }
      
   
   }
   
   
m.appendReplacement(sb, temp1 + "['"+ temp2 + "']");
result = m.find();

}
// Add the last segment of input to
// the new String
m.appendTail(sb);

System.out.println(sb.toString());
      }
}
}

RE: Weird behavior with Rialo
Posted Monday, October 20, 2008 at {ts '2013-05-25 23:13:00'}

Aegis wrote:

just asked one of our devs to paste the regex he used to sort this in here for you.. hopefully he wont be too long


Thank you sir. Much appreciated!

RE: Weird behavior with Rialo
Posted Monday, October 20, 2008 at {ts '2013-05-25 23:35:00'}

Oh nearly forgot, the above will possible break your filepaths in the files *I think, cant be sure if it was this one or not, but either way its only 1 or 2 lines per file that you would have to fix if it was an issue.

In other words, use at your own risk and dont blame me if it breaks Razz

Edited 10/20/08 {ts '2013-05-25 23:39:00'}
RE: Weird behavior with Rialo
Posted Monday, November 17, 2008 at {ts '2013-05-25 07:49:00'}

Gerald,

this is an issue we are long aware of. And we will NOT fix it. Here are the reasons:
Just assume you have the following code:
<cfset a.b["c.d.e.f"] = 1>

Now somewhere later in the code you do something like this:

<cfoutput>#a.b.c.d.e.f#</cfoutput>

Railo will throw an error CF8 not. Here's why:
CF8 will look for the following (in Pseudocode=:
IF variables scope contains key "a.b.c.d.e.f"
display the variables["a.b.c.d.e.f"].
ELSEIF variables scope contains key "a"
If variables["a"] contains key "b"
IF variables["a"]["b"] contains key "c"
IF variables["a"]["b"]["c"] contains key "d"
IF variables["a"]["b"]["c"]["d"] contains key "e"
IF variables["a"]["b"]["c"]["d"]["e"] contains key "f"
Display variables["a"]["b"]["c"]["d"]["e"]["f"]
ELSE
THROW ERROR
END
ELSEIF variables["a"]["b"]["c"]["d"] contains key "e.f"
Display variables["a"]["b"]["c"]["d"]["e.f"]
ELSE
THROW ERROR
END
...
ELSEIF variables["a"]["b"] contains key "c.d.e.f"
Display variables["a"]["b"]["c.d.e.f"]
ELSE
THROW ERROR
END
...
END

So only the bold if case get's involved. And the term #a.b.c.d.e.f# is misleading as well. It suggerates that a contains a key b that contains a key c etc. Which is not the case. a contains a key b and b contains a key c named "c.d.e.f". Respecting the above we did not implement this implicit searching for struct keys since it is very slow and would only affect less than .1% of all the structs and in addition is misleading.

In the case of cffm Rick is defining the keys in the resources cffm.properties file like this: msg.t1, msg.t2 etc. So they are read in JavaRB as keys and when addressed like this: cffm.resourceKit.errorMsg.t11 Railo throws an error.

What I did in order to solve the problem is, that I added a small function to cffm:

<cffunction name="dotNotation2Struct" output="No" returntype="struct">
<cfargument name="resourceKit" type="struct" required="Yes">
<cfset var key = "">
<cfset var dotKey = "">
<cfset var st = arguments.resourceKit>
<cfset var sOldKey = "">
<cfloop collection="#arguments.resourceKit#" item="dotKey">
<cfset st = arguments.resourceKit>
<cfset sOldKey = "">
<cfloop list="#dotKey#" index="key" delimiters=".">
<cfif sOldKey neq "">
<cfset st = st[sOldKey]>
</cfif>
<cfif not structKeyExists(st, key)>
<cfset st[key] = structNew()>
</cfif>
<cfset sOldKey = key>
</cfloop>
<cfset st[sOldKey] = arguments.resourceKit[dotKey]>
<cfset structDelete(arguments.resourceKit, dotKey)>
</cfloop>
<cfreturn arguments.resourceKit>
</cffunction>


Then on top in cffm.cfm after the initialization I called this:
variables.resourceKit = dotNotation2Struct(variables.rbm.getResourceBundle("#variables.rbFile#","#variables.defaultJavaLocale#"));

This converted the dotted keys into inner structs. Then CFFM ran flawlessly and even understands Railo resources like FTP or Amazon S3.

Greetings from Switzerland
Gert Franz
Railo Technologies GmbH
gert.franz@railo.ch
www.railo.ch

Join our Mailing List
german: http://de.groups.yahoo.com/group/railo/
english: http://groups.yahoo.com/group/railo_talk/
linked in: http://www.linkedin.com/e/gis/71368/0CF7D323BBC1

Edited 11/17/08 {ts '2013-05-25 07:50:00'}

New Topic Reply Subscription Options   Previous Page  Page: 1   Previous Page
Subscription Options
Subscription options are available after you log in.

There are 18 active user sessions right now.