cancel
Showing results for 
Search instead for 
Did you mean: 

How to check that my document title is unique before the document creation ?

Benjamin_Jalon1
Elite Collaborator
Elite Collaborator

Hi,

I create my document type with studio and configure the view/edit/creation layout.

How can I refuse the document creation if there is a document with same title into the container and add a red message under the title field to tell there is another document with the same name ?

1 ACCEPTED ANSWER

Benjamin_Jalon1
Elite Collaborator
Elite Collaborator

Hi,

Nuxeo Studio open the world of Nuxeo EP configuration and development for the non-developper users/integrators. Interface is simple and intuitive for functional people.

What you are wanted to do is much more complex for non-developper guy, but easy for developer guy with Nuxeo.

What you want to do is technically create a JSF validator and bind it to the title widget. If you don't understand these notion you will need to get a training session to understand JSF. But you can start by reading this really interesting documentation.

So JSF validator is out of what you can do with Nuxeo Studio and that's why we have created Nuxeo IDE.

Nuxeo IDE is free and documentation is here: http://doc.nuxeo.com/x/ZYKE

You can create with Nuxeo IDE a bundle project easily, see here.

You may know that validator can be a method on a Seam component that can be easily created with Nuxeo IDE. You will not have to declare the validator. You will just have to write yourComponent as validator value.

You will benefit of the Nuxeo IDE Hot Reloading feature during the development and give a really easy way to create your seam component with one click (no more to manage maven dependency, seam.property file, ...)

About the validation code you can use this code:

@In(create = true, required = false)
protected transient CoreSession documentManager;

@In(create = true)
protected transient NavigationContext navigationContext;

public void validate(FacesContext context, UIComponent cmp, Object value) throws ValidatorException {
  DocumentModel currentDocument = navigationContext.getCurrentDocument();

  String title = currentDocument.getPropertyValue("dc:title");
  String query = String.format("SELECT * FROM MyDocumentType WHERE dc:title = '%s' ", title);
  DocumentModelList docs = documentManager.query(query);

  ... etc ...
} 

I will continue that you can add validator directly into widgets you use when you describes form of documents. You have a documentation that explains this point: http://doc.nuxeo.com/x/pgQz

Hope this will help.

View answer in original post

1 REPLY 1

Benjamin_Jalon1
Elite Collaborator
Elite Collaborator

Hi,

Nuxeo Studio open the world of Nuxeo EP configuration and development for the non-developper users/integrators. Interface is simple and intuitive for functional people.

What you are wanted to do is much more complex for non-developper guy, but easy for developer guy with Nuxeo.

What you want to do is technically create a JSF validator and bind it to the title widget. If you don't understand these notion you will need to get a training session to understand JSF. But you can start by reading this really interesting documentation.

So JSF validator is out of what you can do with Nuxeo Studio and that's why we have created Nuxeo IDE.

Nuxeo IDE is free and documentation is here: http://doc.nuxeo.com/x/ZYKE

You can create with Nuxeo IDE a bundle project easily, see here.

You may know that validator can be a method on a Seam component that can be easily created with Nuxeo IDE. You will not have to declare the validator. You will just have to write yourComponent as validator value.

You will benefit of the Nuxeo IDE Hot Reloading feature during the development and give a really easy way to create your seam component with one click (no more to manage maven dependency, seam.property file, ...)

About the validation code you can use this code:

@In(create = true, required = false)
protected transient CoreSession documentManager;

@In(create = true)
protected transient NavigationContext navigationContext;

public void validate(FacesContext context, UIComponent cmp, Object value) throws ValidatorException {
  DocumentModel currentDocument = navigationContext.getCurrentDocument();

  String title = currentDocument.getPropertyValue("dc:title");
  String query = String.format("SELECT * FROM MyDocumentType WHERE dc:title = '%s' ", title);
  DocumentModelList docs = documentManager.query(query);

  ... etc ...
} 

I will continue that you can add validator directly into widgets you use when you describes form of documents. You have a documentation that explains this point: http://doc.nuxeo.com/x/pgQz

Hope this will help.