@fionas76543059 Usage of annotation where extending WCMUsePojo class not a right approach. Please refer below code snippet you may understand using WCMUsePojo
Java
import javax.jcr.Node;
import org.demo.core.models.TextComponentModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.cq.sightly.WCMUsePojo;
public class TextComponent extends WCMUsePojo {
private TextComponentModel model;
@Override
public void activate() throws Exception {
try {
log.info("Text Component 2.0 backend logic starts");
/**
* Initializing the model object to set the values
*/
model = new TextComponentModel();
/**
* Getting the current node from the resource object which is available in Use
* API
*/
Node node = getResource().adaptTo(Node.class);
/**
* Check if the node has title property
*/
if(node.hasProperty("title")) {
/**
* Reading the title property from the string
*/
String title = node.getProperty("title").getString();
/**
* Setting the value entered by the user in the model object
*/
model.setTitle(title);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
/**
* This method is wrapper to return the model object
*
* @return {@link TextComponentModel}
*/
public TextComponent2Model getModel() {
return model;
}
}
HTL
Text Component 2.0 - Showcases Java Use API
<div data-sly-use.text="org.demo.core.cqcomponents.TextComponent">
<h1>Title: ${text.model.title}</h1>
</div>