掲示板

Creating Exception Class

12年前 に Akriti Agrawal によって更新されました。

Creating Exception Class

New Member 投稿: 21 参加年月日: 11/04/21 最新の投稿
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
12年前 に Oliver Bayer によって更新されました。

RE: Creating Exception Class

Liferay Master 投稿: 894 参加年月日: 09/02/18 最新の投稿
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
12年前 に Akriti Agrawal によって更新されました。

RE: Creating Exception Class

New Member 投稿: 21 参加年月日: 11/04/21 最新の投稿
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?
12年前 に Oliver Bayer によって更新されました。

RE: Creating Exception Class

Liferay Master 投稿: 894 参加年月日: 09/02/18 最新の投稿
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
12年前 に Akriti Agrawal によって更新されました。

RE: Creating Exception Class

New Member 投稿: 21 参加年月日: 11/04/21 最新の投稿
Thanks a lot Oliver :-)