Fórumok

Creating Exception Class

Akriti Agrawal, módosítva 12 év-val korábban

Creating Exception Class

New Member Bejegyzések: 21 Csatlakozás dátuma: 2011.04.21. Legújabb bejegyzések
Hi all,

I want to create my own Exception class that checks for the validation of registration number entered by a student but I'm unable to find a way how to extend the liferay's Exception class.

So that if the entered registration number is invalid no account is created for that user. My liferay version is 6.0.5.................its pretty urgent so please help me out

I've added new fields in the create_account.jsp by creating a hook so let me know how to generate the exception and add the values of fields created by me in the databse.


Thanks in advance
Oliver Bayer, módosítva 12 év-val korábban

RE: Creating Exception Class

Liferay Master Bejegyzések: 894 Csatlakozás dátuma: 2009.02.18. Legújabb bejegyzések
Hi Akriti,

I've not done a modification like this but I think you're mixing some of the implementation details emoticon.

1. create a new Exception e.g. "YourOwnException extends PortalException"
2. extend the CreateAccountAction to read your newly added fields
3. if these new fields are empty (or which ever validation you would like) throw a YourOwnException exception
4. add a liferay-ui:error tag to your create an account jsp to display the error message
<liferay-ui:error exception="<%= YourOwnException.class %>" message="language-key-to-describe-your-exception" />

5. to add the new fields to the database you can use custom attributes to extend the user model

HTH Oli
Akriti Agrawal, módosítva 12 év-val korábban

RE: Creating Exception Class

New Member Bejegyzések: 21 Csatlakozás dátuma: 2011.04.21. Legújabb bejegyzések
HI Oliver,

Thanks for your reply

1.Where to find CreateAccountAction?
2.Do I have to create a servicebuilder.xml file?
3.I went through the existing liferay Exception files, each one passes Throwable cause as a parameter value, how to pass this value in my Exception class?
Oliver Bayer, módosítva 12 év-val korábban

RE: Creating Exception Class

Liferay Master Bejegyzések: 894 Csatlakozás dátuma: 2009.02.18. Legújabb bejegyzések
Hi,

regarding your questions:

1. You will find the CreateAccountAction class in the following package: com.liferay.portlet.login.action
2. Yes and no, it depends on the way you want to realize it. If you use custom attributes to extend the user model as suggested above you don't need to run the service builder (your data of the new fields will be stored in expando tables). If you want the data to be listed in the user_ table directly you have to extend the user model via service builder afaik (it's the "harder" way).
3. You don't need to pass a throwable cause to the exception.

Take a look at the CreateAccountAction.processAction method:
  • in the catch block there is a check for a DuplicateUserEmailAddressException (which is thrown in the UserLocalServiceImpl class while trying to add a new user)
  • in UserLocalServiceImpl.verfiyEmailAddress this exception can be thrown if the email already exists, the default constructor of the exception is used without any arguments
  • in com.liferay.portal you will find the DuplicateUserEmailAddressException class

HTH Oli
Akriti Agrawal, módosítva 12 év-val korábban

RE: Creating Exception Class

New Member Bejegyzések: 21 Csatlakozás dátuma: 2011.04.21. Legújabb bejegyzések
Thanks a lot Oliver :-)