Home
Legacy Projects
eXo Portal 2.x
[Resolved] How to...
Search:
eXo Portal 2.x : Legacy projects based on Portal 2.x like DMS 2.x, WCM 1.x, Knowledge Suite 1.x, Collaboration Suite 1.x, ...
Search this topic
Moderator
Join Date:02/02/2009
Posts:95
Last post: 02/03/2012, 04:57 PM
Last Login:02/04/2012, 02:40 PM
[Resolved] How to add a date validator
Posted:Thu,Jul 29,2010, 02:23 PM

Hi,

I'm in DMS 2.3.0

In a dialog template, I have 2 dates. I wish to validate the fact that startDate is prior to endDate

I saw 2 solutions :

- Validators : but actually, I can use validators only in TextField. If I put a validator in CalendarField (validate=myValidator.class), the validator is not launched.

- Interceptors : in wiki, it is said that preInterceptor can be used to validate datas before saving. But if my interceptor detect that endDate is prior to startDate, how can I stop the save of the node ? and re-display the dialog template ? I'm not sure it is possible ?

Have I misunderstood one of theses solutions ? or is there a different way to do ?

 

Thanks,

Romain

__________________
Regards, Romain
Last edited by romain.denarie on Wed,Oct 27,2010, 01:25 PM
Reason: Mark as resolved and change icon
User
Join Date:01/23/2009
Posts:48
Last post: 12/28/2011, 04:16 PM
Last Login:12/29/2011, 10:13 AM
Re: How to add a date validator
Posted:Fri,Jul 30,2010, 04:42 PM

Hello Romain

Here a solution that has been tested on eXo DMS 2.5, and should work on older release to.

 

1- Create an Interceptor that will be executed in "Pre-Save" to control the date

import java.util.Map
import java.util.GregorianCalendar
import javax.jcr.Session
import javax.jcr.Node
import java.text.SimpleDateFormat

import org.exoplatform.services.cms.scripts.CmsScript
import org.exoplatform.services.cms.JcrInputProperty

import org.apache.commons.logging.Log
import org.exoplatform.services.log.ExoLogger
import org.exoplatform.web.application.ApplicationMessage
import org.exoplatform.webui.exception.MessageException

public class MyDateControlPreNodeSaveInterceptor implements CmsScript{

private static final Log LOG = ExoLogger.getLogger("MyDateControlPreNodeSaveInterceptor")

public SPGActuPreNodeSaveInterceptor(){
}

public void execute(Object context) throws Exception{
Map inputValues = (Map) context
GregorianCalendar today =new GregorianCalendar()
GregorianCalendar startDate = inputValues.get("/node/exo:startDate").getValue()
GregorianCalendar endDate = inputValues.get("/node/exo:endDate").getValue()
if(startDate.time >= endDate.time) {
throw new MessageException(
new ApplicationMessage("Start date must be inferior to end date", null, ApplicationMessage.WARNING))
}

}

public void setParams(String[] params) {}

}

 

2- Integrate this interceptor in your dialog code adding this following line at the top of the code

<% uicomponent.addInterceptor("ecm-explorer/interceptor/MyDateControlPreNodeSaveInterceptor.groovy", "prev") ; %>

 With this, the exception is raised and you stay on the dialog.

Regards
 

__________________
Tugdual Grall eXo Platform
Last edited by tgrall on Fri,Jul 30,2010, 04:46 PM
User
Join Date:03/09/2009
Posts:4
Last post: 12/02/2010, 10:41 AM
Last Login:10/05/2010, 07:08 AM
Re: How to add a date validator
Posted:Thu,Aug 05,2010, 07:41 AM
I think, it should better to make the validation work in date field as well. We need that the project is consistent everywhere.
Validations need to be handled by validators only.
Hope you understand.
Moderator
Join Date:02/02/2009
Posts:95
Last post: 02/03/2012, 04:57 PM
Last Login:02/04/2012, 02:40 PM
Re: How to add a date validator
Posted:Tue,Aug 10,2010, 09:23 AM
Tug, this seems to not working on DMS 2.3.0.

After tests, it is working well on DMS 2.5.0

Have you another solution ?
__________________
Regards, Romain
User
Join Date:02/06/2009
Posts:26
Last post: 01/17/2012, 04:05 PM
Last Login:01/17/2012, 04:04 PM
Re: How to add a date validator
Posted:Wed,Aug 11,2010, 07:33 AM

To introduce specific validators in the dialog.gtml, you could follow those steps:
1 / Implement the Validator interface
2 / Put the full path of the Custom Validatore class in the "validate" field.

For example, to add a validator "Float" for a field in the dialog:
1 / Implement this class:
package org.exoplatform.test;
FloatValidator org.exoplatform.webui.form.validator.Validator class implements (
....
)

2 / In my gtmpl, I use:

String [] nameArgs = ["jcrPath = / node / exo: test", "validate = org.exoplatform.test.FloatValidator"];
uicomponent.addTextField ("test", nameArgs);

==>
for further explanation, see this method :

org.exoplatform.ecm.webui.utils.DialogFormUtil.getValidator(String)

Moderator
Join Date:02/02/2009
Posts:95
Last post: 02/03/2012, 04:57 PM
Last Login:02/04/2012, 02:40 PM
Re: How to add a date validator
Posted:Wed,Aug 11,2010, 07:48 AM
Unfortunatly, in DMS 2.3.x and 2.5.x, we cannot use validator on CalendarFields.

It is fixed in ECMS.
__________________
Regards, Romain
User
Join Date:02/06/2009
Posts:26
Last post: 01/17/2012, 04:05 PM
Last Login:01/17/2012, 04:04 PM
Re: How to add a date validator
Posted:Wed,Aug 11,2010, 09:18 AM

Yes, in ECMS, the method  org.exoplatform.ecm.webui.form.UIDialogForm.addCalendarField already use the "validateType" field, so I guess we have to open a new issue in DMS JIRA, to fix this in 2.5.x version.

Last edited by boubaker on Wed,Aug 11,2010, 09:19 AM
Moderator
Join Date:02/02/2009
Posts:95
Last post: 02/03/2012, 04:57 PM
Last Login:02/04/2012, 02:40 PM
Re: How to add a date validator
Posted:Wed,Aug 11,2010, 09:32 AM

Originally Posted by boubaker

we have to open a new issue in DMS JIRA, to fix this in 2.5.x version.

Done

__________________
Regards, Romain
Rules
You can not create topics
You can not post replies
You can not post attachments
You can not edit your posts
Copyright © 2012. All rights reserved,eXo Platform SAS