Skip to content

Commit b861a34

Browse files
committed
CCM-20 #resolve #close
CCM-21 #resolve #close ValidationManager missing singleton persistence
1 parent ea98ac5 commit b861a34

File tree

6 files changed

+65
-32
lines changed

6 files changed

+65
-32
lines changed

config/Coldbox.cfc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
};
4949

5050
// Activate WireBox
51-
wirebox = { enabled = true, singletonReload=true };
51+
wirebox = { enabled = true, singletonReload=false };
5252

5353
// Module Directives
5454
modules = {
@@ -80,6 +80,14 @@
8080
}
8181
];
8282

83+
validation = {
84+
sharedConstraints = {
85+
"sharedUser" = {
86+
username = {required=true, size="6..20"},
87+
password = {required=true, size="6..20"}
88+
}
89+
}
90+
};
8391
}
8492
</cfscript>
8593
</cfcomponent>

handlers/Main.cfc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ component{
2626

2727
}
2828

29+
any function saveShared( event, rc, prc){
30+
// validation
31+
var result = validateModel( target=rc, constraints="sharedUser" );
32+
33+
if( !result.hasErrors() ){
34+
flash.put( "User info validated!" );
35+
setNextEvent('main');
36+
} else {
37+
flash.put( "notice", result.getAllErrors().tostring() );
38+
return index(event,rc,prc);
39+
}
40+
}
41+
2942
// Run on first init
3043
any function onAppInit( event, rc, prc ){
3144

modules/cbvalidation/ModuleConfig.cfc

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ component{
1111
this.author = "Luis Majano";
1212
this.webURL = "http://www.ortussolutions.com";
1313
this.description = "This module provides server-side validation to ColdBox applications";
14-
this.version = "1.0.0[email protected]@";
14+
this.version = "1.0.1[email protected]@";
1515
// If true, looks for views in the parent first, if not found, then in the module. Else vice-versa
1616
this.viewParentLookup = true;
1717
// If true, looks for layouts in the parent first, if not found, then in module. Else vice-versa
@@ -22,7 +22,9 @@ component{
2222
this.modelNamespace = "cbvalidation";
2323
// CF Mapping
2424
this.cfmapping = "cbvalidation";
25-
// Module Dependencies That Must Be Loaded First, use internal names or aliases
25+
// Auto-map models
26+
this.autoMapModels = true;
27+
// Module Dependencies That Must Be Loaded First, use internal names or aliases
2628
this.dependencies = [ "cbi18n" ];
2729
// ColdBox Static path to validation manager
2830
this.COLDBOX_VALIDATION_MANAGER = "cbvalidation.models.ValidationManager";
@@ -31,22 +33,8 @@ component{
3133
* Configure module
3234
*/
3335
function configure(){
34-
3536
// Mixin our own methods on handlers, interceptors and views via the ColdBox UDF Library File setting
3637
arrayAppend( controller.getSetting( "ApplicationHelper" ), "#moduleMapping#/models/Mixins.cfm" );
37-
38-
// Validation Settings
39-
settings = {
40-
// Change if overriding
41-
manager = this.COLDBOX_VALIDATION_MANAGER,
42-
// Setup shared constraints below
43-
sharedConstraints = {
44-
name = {
45-
// field = { constraints here }
46-
}
47-
}
48-
};
49-
5038
}
5139

5240
/**
@@ -58,14 +46,13 @@ component{
5846
parseParentSettings();
5947
// Did you change the validation manager?
6048
if( configSettings.validation.manager != this.COLDBOX_VALIDATION_MANAGER ){
61-
binder.map( "validationManager@cbvalidation" )
49+
binder.map( alias="validationManager@cbvalidation", force=true )
6250
.to( configSettings.validation.manager )
6351
.asSingleton();
6452
}
6553
// setup shared constraints
6654
wirebox.getInstance( "validationManager@cbvalidation" )
6755
.setSharedConstraints( configSettings.validation.sharedConstraints );
68-
6956
}
7057

7158
/**
@@ -110,7 +97,6 @@ component{
11097
if( structKeyExists( validationDSL, "sharedConstraints" ) ){
11198
structAppend( configStruct.validation.sharedConstraints, validationDSL.sharedConstraints, true );
11299
}
113-
114100
}
115101

116102
}

modules/cbvalidation/changelog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
CHANGELOG
22
=========
33

4-
##1.0.0
4+
## 1.0.1
5+
* Force the validation manager binder mapping
6+
* ValidationManager missing singleton persistance
7+
8+
## 1.0.0
59
* Create first module version

modules/cbvalidation/models/ValidationManager.cfc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ vResults = validateModel(target=model);
5050
*/
5151
import cbvalidation.models.*;
5252
import cbvalidation.models.result.*;
53-
component accessors="true" serialize="false" implements="IValidationManager"{
53+
component accessors="true" serialize="false" implements="IValidationManager" singleton{
5454

5555
/**
5656
* WireBox Object Factory
@@ -67,16 +67,18 @@ component accessors="true" serialize="false" implements="IValidationManager"{
6767
*/
6868
property name="sharedConstraints" type="struct";
6969

70+
this.id = createUUID();
71+
7072
/**
7173
* Constructor
7274
* @sharedConstraints.hint A structure of shared constraints
7375
*/
74-
ValidationManager function init(struct sharedConstraints=structNew()){
75-
76+
ValidationManager function init( struct sharedConstraints=structNew() ){
7677
// valid validator registrations
77-
validValidators = "required,type,size,range,regex,sameAs,sameAsNoCase,inList,discrete,udf,method,validator,min,max";
78+
variables.validValidators = "required,type,size,range,regex,sameAs,sameAsNoCase,inList,discrete,udf,method,validator,min,max";
7879
// store shared constraints if passed
7980
variables.sharedConstraints = arguments.sharedConstraints;
81+
8082
return this;
8183
}
8284

@@ -185,24 +187,24 @@ component accessors="true" serialize="false" implements="IValidationManager"{
185187
* Retrieve the shared constraints, all of them or by name
186188
* @name.hint Filter by name or not
187189
*/
188-
struct function getSharedConstraints(string name){
189-
return ( structKeyExists(arguments,"name") ? sharedConstraints[arguments.name] : sharedConstraints );
190+
struct function getSharedConstraints( string name ){
191+
return ( structKeyExists( arguments, "name" ) ? variables.sharedConstraints[ arguments.name ] : variables.sharedConstraints );
190192
}
191193

192194
/**
193195
* Check if a shared constraint exists by name
194196
* @name.hint The shared constraint to check
195197
*/
196-
boolean function sharedConstraintsExists(required string name){
197-
return structKeyExists( sharedConstraints, arguments.name );
198+
boolean function sharedConstraintsExists( required string name ){
199+
return structKeyExists( variables.sharedConstraints, arguments.name );
198200
}
199201

200202

201203
/**
202204
* Set the entire shared constraints structure
203205
* @constraints.hint Filter by name or not
204206
*/
205-
IValidationManager function setSharedConstraints(struct constraints){
207+
IValidationManager function setSharedConstraints( struct constraints ){
206208
variables.sharedConstraints = arguments.constraints;
207209
return this;
208210
}
@@ -212,8 +214,8 @@ component accessors="true" serialize="false" implements="IValidationManager"{
212214
* @name.hint Filter by name or not
213215
* @constraint.hint The constraint to store.
214216
*/
215-
IValidationManager function addSharedConstraint(required string name, required struct constraint){
216-
sharedConstraints[ arguments.name ] = arguments.constraints;
217+
IValidationManager function addSharedConstraint( required string name, required struct constraint ){
218+
variables.sharedConstraints[ arguments.name ] = arguments.constraints;
217219
}
218220

219221
/************************************** private *********************************************/

views/main/index.cfm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@
55
#flash.get( "notice", "" )#
66

77
<form method="post" action="#event.buildLink('main/save')#">
8+
<h1>Local Constraint</h1>
9+
<div class="clearfix">
10+
<label for="name">Username (Required, Length: 6-20)</label>
11+
<div class="input">
12+
#html.passwordField(name="username", value=event.getValue("username",""), size="30")#
13+
</div>
14+
</div>
15+
<div class="clearfix">
16+
<label for="description">Password (Required, Length: 6-20)</label>
17+
<div class="input">
18+
#html.passwordField(name="password", value=event.getValue("password",""), size="30")#
19+
</div>
20+
</div>
21+
<div class="actions">
22+
<input type="submit" class="btn primary" value="Save" tabindex="4">
23+
</div>
24+
</form>
25+
26+
<form method="post" action="#event.buildLink('main/saveShared')#">
27+
<h1>Shared Constraint</h1>
828
<div class="clearfix">
929
<label for="name">Username (Required, Length: 6-20)</label>
1030
<div class="input">

0 commit comments

Comments
 (0)