Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Java use-class getting called twice

Avatar

Avatar
Springboard
Level 4
bilal_ahmad
Level 4

Likes

66 likes

Total Posts

108 posts

Correct Reply

16 solutions
Top badges earned
Springboard
Validate 10
Validate 1
Ignite 1
Establish
View profile

Avatar
Springboard
Level 4
bilal_ahmad
Level 4

Likes

66 likes

Total Posts

108 posts

Correct Reply

16 solutions
Top badges earned
Springboard
Validate 10
Validate 1
Ignite 1
Establish
View profile
bilal_ahmad
Level 4

05-05-2020

Dear members,

 

I'm using AEM 6.4.4 and using wcm-use along with it. The issue is that my use-class activate() method is getting called twice. Anyone has faced this issue before? I tried debugging it but no luck how it's happening. Any help would be really appreciated.

 

Thanks,

Bilal.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
MVP
Theo_Pendle
MVP

Likes

237 likes

Total Posts

251 posts

Correct Reply

105 solutions
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 10
Ignite 1
View profile

Avatar
Validate 1
MVP
Theo_Pendle
MVP

Likes

237 likes

Total Posts

251 posts

Correct Reply

105 solutions
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 10
Ignite 1
View profile
Theo_Pendle
MVP

09-05-2020

Hi @bilal_ahmad,

My first input for this is probably not the answer you're looking for, but... you should think about switching from WCMUse to Sling Models. They allow for more features, are easier to use and are the current best practice for AEM component models. They are better documented and these days I think most people are more used to Sling Models so you're likely to get more and better answers if you ask a question 😉 This would be a good candidate for an upgrade, you may find that it solves your problem!

However, sticking to WCMUse for now:

  1. If your activate() method is being called twice, the most likely reason is that there are two requests being made. How are you making the request to the model? For example, if you have a test page with a bunch of components on it and you are loading that page to test, is it possible that there are 2 components that use the CommonUtilUse model and therefore it is being called twice?
  2. Are you using CommonUtilUse.java anywhere in your Java code (even if you are not directly calling activate())? Becuase activate() is called automatically in some scenarios, so perhaps you are indirectly calling it via your SuperScriptUse.java class or something along those lines?

 

Answers (4)

Answers (4)

Avatar

Avatar
Ignite 1
MVP
Ankur_Khare
MVP

Likes

159 likes

Total Posts

370 posts

Correct Reply

58 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Give Back 50
Give Back 5
View profile

Avatar
Ignite 1
MVP
Ankur_Khare
MVP

Likes

159 likes

Total Posts

370 posts

Correct Reply

58 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Give Back 50
Give Back 5
View profile
Ankur_Khare
MVP

09-05-2020

You can try one thing change the name of your model.

And update the same in your sightly code and see.

 

In this way you will be able to confirm its getting called from somewhere else inbyour code.

Avatar

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

121 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

121 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile
Veena_Vikram
MVP

05-05-2020

Can you give a sample of the code how you are invoking the class and just a skeleton of your class (remove any main business logic ) ?

bilal_ahmad
Thank you so much Veena. for responding to my issue, also apologies for the delayed response.
bilal_ahmad

Thank you so much Veena. for responding to my issue, also apologies for the delayed response. I'll attach the files here:

 

 

<sly data-sly-use.commonutilobj="${'com.mysite.aem.core.use.CommonUtilUse'}"/>
<div id="${commonutilobj.componentId}" data-tracking-event-label="${commonutilobj.componentLabel}" class="jumbotron ${!properties.backgroundColor ? '': '{0}{1}' @format=[properties.backgroundColor,'-bg']} ${properties.paddingTop} ${properties.paddingBottom} ${properties.alwaysShowImg ? 'alwaysImg' : ''} ${!properties.fileReferencebckgroundimage ? '' : '{0}{1}{2}' @ format=['backgroundImg-',properties.horizontalAlign, properties.verticalAlign]} ${properties.alignment}" style="background-image: url('${properties.fileReferencebckgroundimage @ context='uri'}')"> 
    <div class="wrapper">
		<div class="row" data-sly-test="${properties.H3Title || properties.H5Eyebrow || properties.leadPara}">
			<div class="col-md-8 ${properties.alignment=='text-center'? 'mx-auto':''}">
				<h5 data-sly-test="${properties.H5Eyebrow}" class="alt ${properties.H5EyebrowColor}">${properties.H5Eyebrow ='unsafe'}</h5>
				<h3 data-sly-test="${properties.H3Title}" class="${properties.H3TitleColor}"
					data-sly-use.supuse="${'com.mysite.aem.core.components.use.SuperScriptUse' @ param=properties.H3Title}">${supuse.highlight ='unsafe'}</h3>
				<p data-sly-test="${properties.leadPara}" class="lead2 ${properties.leadParaColor}">${properties.leadPara ='unsafe'}</p>
			</div>
		</div>
	</div>
</div>

 

wcm-use-error.PNG

Veena_Vikram
I don't see an issue in your code. How did you figure out it is getting called twice ?
bilal_ahmad

Thanks for the response, Veena_07
Here's how I found out - I have created a page with only one component(this one) on it.  I start my AEM instance in debug mode and placed a breakpoint at activate() method. when I refresh the page, the control comes to the activate method, it executes, then it gets called again and gets processed. Many Thanks, Bilal.

Avatar

Avatar
Validate 1
MVP
ArpitVarshney
MVP

Likes

135 likes

Total Posts

185 posts

Correct Reply

36 solutions
Top badges earned
Validate 1
Establish
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Validate 1
MVP
ArpitVarshney
MVP

Likes

135 likes

Total Posts

185 posts

Correct Reply

36 solutions
Top badges earned
Validate 1
Establish
Give Back 5
Give Back 3
Give Back 25
View profile
ArpitVarshney
MVP

05-05-2020

Hi @bilal_ahmad 

 

There must be issue in your custom code as there is no such issue identified in AEM OOB.

You need to debug your code or share your code(HTL+Java) sample for better understanding.

 

Regards,

Arpit

bilal_ahmad

Thank you Arpit, for your response. I tried debugging it but the only clue I got is that my activate() method got called twice 😞

Here are my files for your reference:

 

<sly data-sly-use.commonutilobj="${'com.mysite.aem.core.use.CommonUtilUse'}"/>
<div id="${commonutilobj.componentId}" data-tracking-event-label="${commonutilobj.componentLabel}" class="jumbotron ${!properties.backgroundColor ? '': '{0}{1}' @format=[properties.backgroundColor,'-bg']} ${properties.paddingTop} ${properties.paddingBottom} ${properties.alwaysShowImg ? 'alwaysImg' : ''} ${!properties.fileReferencebckgroundimage ? '' : '{0}{1}{2}' @ format=['backgroundImg-',properties.horizontalAlign, properties.verticalAlign]} ${properties.alignment}" style="background-image: url('${properties.fileReferencebckgroundimage @ context='uri'}')"> 
    <div class="wrapper">
		<div class="row" data-sly-test="${properties.H3Title || properties.H5Eyebrow || properties.leadPara}">
			<div class="col-md-8 ${properties.alignment=='text-center'? 'mx-auto':''}">
				<h5 data-sly-test="${properties.H5Eyebrow}" class="alt ${properties.H5EyebrowColor}">${properties.H5Eyebrow ='unsafe'}</h5>
				<h3 data-sly-test="${properties.H3Title}" class="${properties.H3TitleColor}"
					data-sly-use.supuse="${'com.mysite.aem.core.components.use.SuperScriptUse' @ param=properties.H3Title}">${supuse.highlight ='unsafe'}</h3>
				<p data-sly-test="${properties.leadPara}" class="lead2 ${properties.leadParaColor}">${properties.leadPara ='unsafe'}</p>
			</div>
		</div>
	</div>
</div>

 

 

 

wcm-use-error.PNG

ArpitVarshney

Hi @bilal_ahmad 

 

I don't see any reason why your activate method is calling twice.

You are using two wcmuse classes in HTL. Can you clarify which one's activate method is getting called twice? and also make sure that in your java code you're not calling activate method manually from another method.

 

Regards,

Arpit

 

bilal_ahmad
CommonUtilUse is the WCMUse that I'm talking about. It gets called twice. I removed other pieces from the html file so that only my < sly data-sly-use.commonutilobj ="${'com.mysite.aem.core.use.CommonUtilUse'}" /> gets called. Still I see it getting called twice. However I' m not calling the activate method in this java class/any other java class 😞
ArpitVarshney

@bilal_ahmad As you already mentioned that it is only happening for CommonUtilUse class and not for the other one which confirms that there is an issue in your custom code, not an issue AEM known issue.

Whatever code you have shared there is no such code that confirms that it is getting called twice. You need to check and debug your whole code to identify the issue.

 

Regards,

Arpit

bilal_ahmad

Thank you @ArpitVarshney, but CommonUtilUse is called only once from this component on this html. I have created a page where there's only one component, this one and then i'm seeing it getting called twice. I have, however other components which use the same java class but if I include them on my page, number of calls further increase in multiple of 2.

Avatar

Avatar
Ignite 1
MVP
Ankur_Khare
MVP

Likes

159 likes

Total Posts

370 posts

Correct Reply

58 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Give Back 50
Give Back 5
View profile

Avatar
Ignite 1
MVP
Ankur_Khare
MVP

Likes

159 likes

Total Posts

370 posts

Correct Reply

58 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Give Back 50
Give Back 5
View profile
Ankur_Khare
MVP

08-05-2020

Check your sightly code .

You must be calling your model twice