Expand my Community achievements bar.

SOLVED

RTE formatting

Avatar

Level 2

Text formatting not working:

 
JeetendrakumarSa_0-1727368289964.png
I added the correct code:
public String getText() {
return TextUtil.reformatText(text);
}
 
Any suggestion?
1 Accepted Solution

Avatar

Correct answer by
Level 2

HI @narendiran_ravi, issue finally found not in the AEM, that need to check in the front-end code

View solution in original post

9 Replies

Avatar

Community Advisor

Well, first of all you need to make sure your SlingModel is initiated... and then your using the correct Sling Annotations to pull jcr properties into that component. like @ValueMapValue private String text;... next, you need to ensure that your TextUtil is also working as expected.

 

 

HTL
<a href="${model.urlLink}">${model.formattedText}</a>

Sightly
...
@ValueMapValue
private String urlLink;
@ValueMapValue
private String text;

public String getUrl() {
   return LinkUtils.formatLink(urlLink);
}

public String getFormattedText() {
   return TextUtil.reformatText(text);
}

 

 

 

for testing sale, making sure if your Sling Model is returning string from the backend as expected, you can do something like this:
public String getFormattedText() {
   return "I love sourcedcode.com!";
}

 

References (Sling Model Annotations CheatSheet): https://sourcedcode.com/blog/aem/aem-sling-model-injectors-annotations-cheat-sheet-reference-guide#V...

 

 

Avatar

Community Advisor

Hello, your link TextUtil must be not working as expected…. 

you can simple return hard coded text, to see if the method is retuning anything correct, and if so, must be your TextUtil. Something is not working there. 

public String getFormattedText() {
   return "I love sourcedcode.com!";
}

Avatar

Level 2

I tested it. Yes, there might be some issues with TextUtil or somewhere else but not fully sure as it works in other places.

JeetendrakumarSa_0-1727413693093.png

Is there any other option to handle this formatting?

Avatar

Community Advisor

Hey, sorry nope, your own custom solution is required. 

Avatar

Community Advisor

When you say it is not working. Could you elaborate that a little ? 

Avatar

Level 2

For example, the formatting is applied to the text field which is working fine in 1 component but not working for the other.

Avatar

Level 5

You can debug or add logs to see if the Util method gives the expected output.

Avatar

Correct answer by
Level 2

HI @narendiran_ravi, issue finally found not in the AEM, that need to check in the front-end code