Foren

Server side validation on structure field

thumbnail
mohit mehral, geändert vor 6 Jahren.

Server side validation on structure field

New Member Beiträge: 17 Beitrittsdatum: 16.03.17 Neueste Beiträge
Dear All,

Our requirement is to put server side validation on one of the field on structure.

i.e. we have one structure which is having field employee id.
We need to check if entry with same is already done in our structure data.i.e. article.
If yes, we want to show error message of duplicate.

We are using liferay DXP.
thumbnail
mohit mehral, geändert vor 6 Jahren.

RE: Server side validation on structure field

New Member Beiträge: 17 Beitrittsdatum: 16.03.17 Neueste Beiträge
Did anyone faced with similar requirement?
If yes, requesting to please revert.
We are using liferay dxp version.

Regards,
Mohit
thumbnail
Andrew Jardine, geändert vor 6 Jahren.

RE: Server side validation on structure field

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
Hi Mohit,

I have not done this before but I an tell you that you are certainly not the first person to ask for it. I know that in 7 you can define your own custom field types, but I think that functionality might be limited to the new Forms application (not the same as WCM). If that is the case, then I would consider trying something a little trickier.

You could create a Theme Contributor that could carry with it some JS. That JS could be used to attach itself to an element on the page with a specific ID (that part you would need to figure out -- what does Liferay call the form field for employeeId -- I would be that it is consistent in pattern). Once you have found the element, you could attach a onBlur event to it which you could then use to perform the check, and then based on the results, do something to manipulate the DOM, or show an alert modal or something.

That's what I would try at least.
thumbnail
mohit mehral, geändert vor 6 Jahren.

RE: Server side validation on structure field

New Member Beiträge: 17 Beitrittsdatum: 16.03.17 Neueste Beiträge
Thanks for reply.

Approach which you have given is client side /javascript validation.
Is there any way to do it using server side validation, as normal VAPT(Security testing) validations should be present on server side rather than at client side.


Regards,
Mohit
thumbnail
Christoph Rabel, geändert vor 6 Jahren.

RE: Server side validation on structure field

Liferay Legend Beiträge: 1554 Beitrittsdatum: 24.09.09 Neueste Beiträge
You could try to create a service hook like this one for the user:
https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/customizing-liferay-services-service-wrappers
https://docs.liferay.com/ce/apps/web-experience/latest/javadocs/com/liferay/journal/service/JournalArticleLocalServiceWrapper.html

It would require you to parse the content and throw some kind of error. You probably would have to do something on the frontend to display the error in a nice way so that your editors won't know what they did wrong.