|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +# Lucee 6 |
| 6 | + |
| 7 | +Lucee comes with a lot of new features and functionality that improve your interaction with Lucee both directly through new features and indirectly by enhancing the existing ones. The focus as always is not simply to add functionality that you can achieve yourself with CFML code but to enhance the language itself. |
| 8 | + |
| 9 | +Stay tuned as we explore the exciting world of Lucee 6. Get ready to elevate your CFML game with the latest and greatest. |
| 10 | + |
| 11 | +## Java |
| 12 | + |
| 13 | +Lucee now offers an array of enhanced functionalities for a more seamless integration between Lucee and Java applications and code. |
| 14 | + |
| 15 | +### Java Code inside CFML! |
| 16 | + |
| 17 | +In Lucee 6 you have the flexibility to incorporate Java code directly within your CFML code opening up new possibilities for seamless integration. |
| 18 | + |
| 19 | +#### Within a User Defined Function (UDF): |
| 20 | + |
| 21 | +```java |
| 22 | +int function echoInt(int i) type="java" { |
| 23 | + if(i==1) throw new Exception("Oopsie-daisy!!!"); |
| 24 | + return i*2; |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +Simply add the attribute `[type="java"]` and you can effortlessly embed Java code within your CFML template. |
| 29 | + |
| 30 | +#### Or in a Closure: |
| 31 | + |
| 32 | +```java |
| 33 | +to_string = function (String str1, String str2) type="java" { |
| 34 | + return new java.lang.StringBuilder(str1).append(str2).toString(); |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +Please note that this feature isn't supported for Lambda Functions as the Lambda Syntax conflicts with the attribute "type=java". |
| 39 | + |
| 40 | + |
| 41 | +### Components |
| 42 | + |
| 43 | +In Lucee 6, we've expanded your options by introducing sub-components, a powerful addition to your CFML toolkit. Unlike traditional components defined in separate .cfc files, sub-components reside within the same template as the main component, offering you increased flexibility and improved code organization. |
| 44 | + |
| 45 | +#### Why Use Sub Components? |
| 46 | + |
| 47 | +Sub-components bring several benefits to the table: |
| 48 | + |
| 49 | +- **Modularization**: Sub-components enable you to break down complex components into smaller, more manageable pieces. This modular approach simplifies development, testing, and maintenance. |
| 50 | +- **Reusability**: Components that are used across multiple templates can be encapsulated as sub-components. This reusability reduces code duplication and promotes a DRY (Don't Repeat Yourself) coding practice. |
| 51 | +- **Scoped Variables**: Sub-components can access variables within the parent component's scope, simplifying data sharing between related components. |
| 52 | +- **Improved Collaboration**: In team projects, sub-components can make it easier for developers to work on specific parts of a component without affecting the entire structure. This promotes collaboration and concurrent development. |
| 53 | +- **Code Organization**: Sub-components help maintain a clean and organized codebase by keeping related functionality together within a single template. |
| 54 | +- **Testing Isolation**: When unit testing components, sub-components can be tested in isolation, allowing for more targeted and granular testing. |
| 55 | +- **Easier Debugging**: Smaller, focused sub-components can make debugging more straightforward since you can pinpoint issues within specific sections of your code. |
| 56 | +- **Version Control**: Sub-components can be managed and version-controlled independently, providing more control over changes and updates. |
| 57 | +- **Performance Optimization**: In certain cases, splitting functionality into sub-components can lead to more efficient code execution, especially when components are conditionally loaded based on specific use cases. |
| 58 | +- **Simplified Component Management**: With sub-components, you can manage related code within a single template, making it easier to locate and edit all associated functionality. |
| 59 | + |
| 60 | +These additional benefits highlight the versatility and advantages of using sub-components in your CFML applications. |
| 61 | + |
| 62 | +#### Example of Sub Component Definition: |
| 63 | + |
| 64 | +```cfml |
| 65 | +component { |
| 66 | + function mainTest() { |
| 67 | + return "main"; |
| 68 | + } |
| 69 | +} |
| 70 | +
|
| 71 | +component name="Sub" { |
| 72 | + function subTest() { |
| 73 | + return "sub"; |
| 74 | + } |
| 75 | +} |
| 76 | +
|
| 77 | +// Usage example |
| 78 | +cfc = new MyCFC(); |
| 79 | +echo("main -> " & cfc.mainTest()); |
| 80 | +echo("<br>"); |
| 81 | +
|
| 82 | +cfc = new MyCFC$Sub(); |
| 83 | +echo("sub -> " & cfc.subTest()); |
| 84 | +echo("<br>"); |
| 85 | +``` |
| 86 | + |
| 87 | +Sub-components expand your horizons and provide new avenues for structuring your CFML code effectively. |
0 commit comments