I'm new to AEM development and got a requirement to extend the Textfield Unique validation for all Content fragment models to work in a case-insensitive manner. Like it should consider the Person and person as the same and show a unique value error message. Can anyone please suggest if it is possible to do this by making some configuration changes or how can we do this customization? Thanks in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @MukeshAEM,
Unfortunately this is not configurable.
In general Unique validation option is handled by com.adobe.cq.dam.cfm.impl.servlets.UniqueFieldValidatorServlet.
As it can be seen on above screen shot UniqueFieldValidatorServlet is registered on specific extension, resourceType and support GET method.
What you can do, is to create your own custom servlet with your logic that will be used instead of OOTB one. Below is sample code snippet. Make sure to set high ranking - this will guarantee your servlet will be used instead of OOTB.
@Component(service = { Servlet.class })
@SlingServletResourceTypes(
resourceTypes="dam/cfm/editor/validator/uniquefield",
methods= HttpConstants.METHOD_GET,
extensions="json")
// setting high ranking value to make sure custom servlet will be used instead of OOTB
@ServiceRanking(Integer.MAX_VALUE)
public class CustomUniqueFieldValidatorServlet extends SlingSafeMethodsServlet {
@Override
protected void doGet(final SlingHttpServletRequest req,
final SlingHttpServletResponse resp) throws ServletException, IOException {
// place for your code
}
}
Your custom servlet has to consume below 3 params:
Above params will be passed automatically to your servlet as part of GET request query string.
Please also be aware that com.adobe.cq.dam.cfm.impl.servlets.UniqueFieldValidatorServlet is not exported so you will not be able to extend this servlet directly and use code from it. You have to build entire logic by yourself.
Last but not least, if you decide to write your own servlet it has to return results in proper json format, here is an example
{
"fieldName":"title",
"fragmentPath":"/content/dam/test/my-cf-2",
"value":"Adobe",
"isValid":false,
"references":[
{
"path":"/content/dam/test/my-cf-1",
"title":"my-cf-1"
}
]
}
You can also check format of result json and request parameters using web tools in your browser.
Hi @MukeshAEM,
Unfortunately this is not configurable.
In general Unique validation option is handled by com.adobe.cq.dam.cfm.impl.servlets.UniqueFieldValidatorServlet.
As it can be seen on above screen shot UniqueFieldValidatorServlet is registered on specific extension, resourceType and support GET method.
What you can do, is to create your own custom servlet with your logic that will be used instead of OOTB one. Below is sample code snippet. Make sure to set high ranking - this will guarantee your servlet will be used instead of OOTB.
@Component(service = { Servlet.class })
@SlingServletResourceTypes(
resourceTypes="dam/cfm/editor/validator/uniquefield",
methods= HttpConstants.METHOD_GET,
extensions="json")
// setting high ranking value to make sure custom servlet will be used instead of OOTB
@ServiceRanking(Integer.MAX_VALUE)
public class CustomUniqueFieldValidatorServlet extends SlingSafeMethodsServlet {
@Override
protected void doGet(final SlingHttpServletRequest req,
final SlingHttpServletResponse resp) throws ServletException, IOException {
// place for your code
}
}
Your custom servlet has to consume below 3 params:
Above params will be passed automatically to your servlet as part of GET request query string.
Please also be aware that com.adobe.cq.dam.cfm.impl.servlets.UniqueFieldValidatorServlet is not exported so you will not be able to extend this servlet directly and use code from it. You have to build entire logic by yourself.
Last but not least, if you decide to write your own servlet it has to return results in proper json format, here is an example
{
"fieldName":"title",
"fragmentPath":"/content/dam/test/my-cf-2",
"value":"Adobe",
"isValid":false,
"references":[
{
"path":"/content/dam/test/my-cf-1",
"title":"my-cf-1"
}
]
}
You can also check format of result json and request parameters using web tools in your browser.