cancel
Showing results for 
Search instead for 
Did you mean: 

Property Constraints

rich_weiskopf
Champ in-the-making
Champ in-the-making
Version: 1.3.0dev
Where do I specify a constraint for a property in a property sheet; which config file?

Rich
11 REPLIES 11

gavinc
Champ in-the-making
Champ in-the-making
Constraints for properties are defined in the model.

For the core cm: model, you'll need to look at projects/repository/config/model/contentModel.xml.

anweber
Champ in-the-making
Champ in-the-making
Hi,

  In fact, we can see an example of the definition of a constraint in "contentModel.xml" (in the Alfresco 1.3 Community Preview Released).  Is the way we can define such constraints described somewhere?  Is it possible to define constrains between different properties.  Can we use other languages than REGEX to express constraints.

   The example included in ContentModel.xml  contains in the REGEX expression some escaped chars where it is not really necessary for a valid regex expression :
.*[\"\*\\\>\<\?\/\:\|\xA3\xAC\%\&\+\;]+.*
Could be written more simply :
.*["*\><?/Smiley Indifferent\xA3\xAC%&+;].*

      Regards,

               Andre

gavinc
Champ in-the-making
Champ in-the-making
Hi,

Thanks for the suggestions for the regular expression, anything to make them look less complex is a good thing  Smiley Happy

There is currently no support for defining constraints between properties.

Unfortunately, there isn't any supporting documentation at the moment for defining custom constraints.

As a starting point the constraint implementations are registered in projects\repository\source\java\org\alfresco\repo\dictionary\M2ConstraintDefinition.java. It will be a case of copying an existing constraint and modifying for your scenario.

vincent_os
Champ in-the-making
Champ in-the-making
Hello,

Can I confirm my understanding here in relation content validation using REGEX.

If I define a REGEX constraint as per example here: http://wiki.alfresco.com/wiki/Content_Model_Constraints
Does Alfresco take the REGEX constraint defined in the content model and apply it using client side java script? (as per explanation: "… The Alfresco Web Application UI has built-in javascript translation to enforce constraints on the browser clients for the built-in types. See org.alfresco.web.bean.generator.BaseComponentGenerator for more examples.")


With thanks,
Vincent.


mitpatoliya
Star Collaborator
Star Collaborator
yes , your understanding is correct.

Thank you for your reply.

The client side regex validation is not working for me. When I attempt to edit data in a data list that is associated with a regex validation, I would expect the "save" button to become disabled in the event the entered data violates the regex constraint. This is not happening. What does happen is that the update will fail as the regex seems to be applied during the update operation on the backend, generating the generic message "Could not update data item".

One more thing, in our deployment we have the "Share" and "Alfresco" web applications running on two separate Tomcat container instances.

Can you go into the mechanism by which the client side java script works. I am guessing that at deployment time the model.xml is parsed and the regex extracted and client side java script is generated? Or does the client invoke a server side validation webservice using ajax as I am editing in data in the browser?

Does our two container deployment configuration (described above) interfere with the client side validation?

With thanks,
Vincent

mitpatoliya
Star Collaborator
Star Collaborator
Actually I missed that validation done on server side You will find following line in the link you have posted.
Constraint checks are applied during integrity checks, typically at the end of a transaction within the server.
This should give you idea about how validation is handled.

OK, so the regex validation seems to be done both on the client side and server side. Ok makes sense (belt and braces).

For me, the server side validation is working, the client side is not. I would like to understand how the client side validation mechanism is implemented. Is it:

A) Java script generated from the regex defined in the model and somehow made available to the browser, and if so how.

B) A client side ajax call to a backend validation webservice

C) Something else


Thanks,
Vincent

OK, I have found the following: http://wiki.alfresco.com/wiki/Forms_Developer_Guide#Introduction
which explains the client side validation. Is it possible to verify that my regex constraint is getting loaded by the browser by inspecting the client side javascript files loaded by the browser using something like Firebug?