Railo Administrator - Settings
Yesterday I presented a part of the architecture of Railo concerning the separation of webs. Next I will post something about the new features invented in Railo and beeing configurable in the Web Administrator. We start with the settings section.Regional settings
Railo offers you to set up your regional settings according to your applications requirements. You can for instance host Railo somewhere in Europe having an application that is used only in a certain area the US. Then you need to convert all the time and date values to the local time of the host server to the local time of the applications usage area. This would be done by using the DateAdd() function. But with Railo you can just set the local time of your server to any desired time zone.After setting this value you Railo offers two functions in order to obtain the current time: now() and nowServer(). While now() returns the current Railo time (depending on the region you chose), nowServer() returns the current time of the server itself.
Another cool feature is the definition of a time server where Railo synchronizes the server time with.
In addition to that you can define the default encoding of a page and the default locale for formatting values.
Component
When you create a new component it allways inherits a base component. By inheriting this base component your component inherits all attributes and methods defined in the base component. So if you would like to add functionality to all of your components you just have to add the functionality to the base component. By setting the default base/root component you can define which component is to be used as the ancestor for all your components.When you call a Railo Component directly via an url, then a dump template is beeing used in order to display the components contents. If you would like to change the layout of the component dump you can either change the file that is used for the dump or write your own dump template and address it here in this setting.
Now comes a tricky one. In object orientated languages encapsulation is one of the main principles. This principle declares amongst others that any variable that is declared inside a class is not accessible from outside. Means that all variables from the this scope are private, unless you declare them explicitly as public.
Coldfusion does not behave in this way. All variables in the this scope of a component are accessible from outside. So just look at the following code:
file test.cfc:
<cfcomponent>
<cfset this.name = "Roger">
<cffunction ...>
</cffunction>
</cfcomponent>
file test.cfm:
<cfset oTest = createComponent("component", "test")>
<cfdump eval="oTest">
The ouput delivers the following.| oTest | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
| oTest | ||||||||||||||||||||||
| ||||||||||||||||||||||
Scope
One of the main things regarding readability of code and performance improvements is the scope cascading. CFMX offers the nice features of searching variables in different scopes while accessing an unscoped variable. Just have a look at the following (I must admit, stupid) code:1: <cfset cookie.name = "Roger">
2: <cfset form.name = "Smith">
3: <cfset st = StructNew()>
4: <cfloop from="1" to="100000" index="i">
5: <cfset st[i].name = name>
6: </cfloop>Since the variable in line 5 is not scoped and CFMX (and Railo by default) searches the scopes for a variable named name in the following order: variables -> cgi -> url -> form -> cookie, st[i].name will allways be "Smith" since the form scope which is scanned before the cookie scope contains a variable called name which value is set to Smith.
Now if in line 5 you would write:
5: <cfset st[i].name = cookie.name>then the result would be different. Not only for readability reasons scoping variables is adviseable. If in the above example you delete line 2
2: <cfset form.name = "Smith">
...
5: <cfset st[i].name = name>and leave line 5 as is then the difference in execution time between scoped and unscoped code is 75%. OK it's an extreme example but it should show the necessity of scoping variables.
Railo can force you to scope variables by allowing you do deactivate scope cascading. The result above would throw an error of trying to use an undefined variable called "name".
The same type of coding requirement can be achieved by disabling the search of variables in all available queries.
If you deactivate the cascade to resultset feature following code would throw an error.
<cfquery name="getCustomers" datasource="cust">
SELECT firstName, lastName FROM Customers
</cfquery>
<cfloop query="getCustomers">
<cfoutput>#firstName#&nbsp;#lastName#</cfoutput>
</cfloop>If you like to cluster Railo, you need to set the session type to "J2EE" in order to use the clustering capabilities of the used application servers.
Since the rest of the settings in the scope section are similar to those of CFMX and BD, I will not address them any further.
4 responses so far ↓
1 John Farrar // Dec 22, 2006 at 5:51 AM
2 Gert Franz // Dec 22, 2006 at 9:00 AM
you can just set the setting to private in the Railo administrator. We have no special code for setting variables private or protected. You have only an influence on the default setting at the moment. But we are open for suggestions.
Gert
3 John Farrar // Dec 22, 2006 at 3:02 PM
4 Streit // Dec 23, 2006 at 1:18 AM
In other CFML Engines you can only have all data members (properties) of a component as public and there is no way to change this, from our view this is very bad decision, because that we have made the possibility to change the access level for data members.
For example the railo source code has x 1000 classes and there is not a hand full of data members that are not private.
Form our view data members should be always private and you should only access fom outside via function members (getters,setters), with this "accessor" functions you will also have the possibility to control the access. this is a usual practise (and more) in java and should also be one in cf (http://en.wikipedia.org/wiki/JavaBeans).
Let me make a example
<code>
<cfcomponent>
<!--- private data memers --->
<cfset this.lastname="Miller">
<cfset this.firstname="Peter">
<cfset this.age=101>
<cffunction name="getLastName" access="public">
<cfreturn this.lastname>
</cffunction>
<cffunction name="setLastName" access="public">
<cfargument name="lastname">
<cfset this.lastname=arguments.lastname>
</cffunction>
<cffunction name="getFirstName" access="package">
<cfreturn this.firstname>
</cffunction>
</cfcomponent>
</code>
at this example you can see, there are 3 data members, with 3 different access level (via functions members).
lastname has a public "access function", firstname a package only "access function" and age is private because there is no "access function".
firtname is readonly because there is no "setter" and lastname is also writable, because there is a setter avaiable.
you can get a much control over the different data member you not only can control the access level you also have the possibiity to control if a data member ist readonly or not.
Railo 1.1 will also bring the possibility to make "shorthand" calls for commponent, that are already avaibale for java objects.
a "shorthand" call is when you call a data member "myComponent.lastname"
and this data members is not accesibility (because it is private or doesnt exist), railo will check if there is a "getter" (getLastname) with a matching name and call this getter.
greetings michael
Leave a Comment