What all the object available ootb in granite rendercondition dialog | Community
Skip to main content
Level 2
May 13, 2025
Solved

What all the object available ootb in granite rendercondition dialog

  • May 13, 2025
  • 4 replies
  • 669 views

Hi All,

What all the ootb objects available in granite rendercondition.

I have browsed and few of the blog mentioned requestPathinfo is available so like this What other ootb objects available in granite rendercondition to use in component dialog.

 

 

4 replies

giuseppebaglio
Level 10
May 14, 2025

hi @amitsi18,

The granite render condition is marked with "@Model," indicating that it is a Sling Model. You can utilise all the available injectors and the out-of-the-box (OOTB) global objects as outlined in the documentation. Here are some examples demonstrating how different Java objects are injected into the implementation:

https://ankanghosh-webdev.medium.com/granite-render-condition-in-aem-64d32f03a7d1

https://jpsoares.medium.com/aem-granite-render-conditions-438c804b1e5a

 

Level 4
May 14, 2025

Hi @amitsi18 ,

Like you are using requestPathInfo there are many ootb objects in aem which you can access In AEM. You can access all the objects which are injected in a sling model. So there are many objects like SlingHttpServletRequest, Resource, ValueMap, ResourceResolver, Session, and Authorizable for user and request context. You can also access RequestPathInfo for URL details, WCMMode for authoring modes, and Page, PageManager for page-related context. Additionally, Component, ComponentContext, and Bindings are available to control field visibility dynamically based on user roles, request parameters, and authoring mode.

AmitVishwakarma
Community Advisor
Community Advisor
May 14, 2025

Hi @amitsi18 ,

 

In Granite RenderCondition (used in AEM dialogs to conditionally show/hide fields), the underlying implementation uses Sling Models, meaning you have access to all Sling injectable objects that apply in the context of a dialog rendering request.

Complete list of OOTB objects that you can inject into a Granite RenderCondition class using Sling Models:

AmitSi18Author
Level 2
May 15, 2025

@giuseppebaglio @shivamkumar @amitvishwakarma 

I am just trying to understand this.

I have not written and custom servlet or sling model for requestPathInfo but I am still able to use it in rendercondition expression(refer below code). But other object are not available like resource, request etc... mentioned by @amitvishwakarma 

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Properties"
sling:resourceType="cq/gui/components/authoring/dialog" xmlns:granite="http://www.adobe.com/jcr/granite/1.0">
<content
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
<items jcr:primaryType="nt:unstructured">
<column
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<text
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldLabel="Text"
name="./text"/>
<myTextField
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldDescription="This is a conditional text show hide text field"
fieldLabel="My Text Field"
name="./myTextField">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:containsIgnoreCase(requestPathInfo.suffix, '/en/home-page')}"/>
</myTextField>>
</items>
</column>
</items>
</content>
</jcr:root>

@Model(adaptables = Resource.class)
public class HelloWorldModel {

@ValueMapValue(name=PROPERTY_RESOURCE_TYPE, injectionStrategy=InjectionStrategy.OPTIONAL)
@Default(values="No resourceType")
protected String resourceType;

@SlingObject
private Resource currentResource;

@SlingObject
private ResourceResolver resourceResolver;

private String message;

@ValueMapValue(injectionStrategy=InjectionStrategy.OPTIONAL)
private String text;

@PostConstruct
protected void init() {
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
String currentPagePath = Optional.ofNullable(pageManager)
.map(pm -> pm.getContainingPage(currentResource))
.map(Page::getPath).orElse("");

message = "Hello World!\n"
+ "Resource type is: " + resourceType + "\n"
+ "Current page is: " + currentPagePath + "\n";
}

public String getMessage() {
return message;
}
}
arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
May 16, 2025