Created
September 30, 2025 13:24
-
-
Save VivekSaha/8d27c46aef812b8b799d5cdf9161aa6d to your computer and use it in GitHub Desktop.
AEM - Text Field Component using Sling Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //C:\aem-project\aemgeeks\core\src\main\java\com\aemgeeks\core\models\TextfieldSampleComponentModel.java | |
| package com.aemgeeks.core.models; | |
| import org.apache.sling.api.resource.Resource; | |
| import org.apache.sling.models.annotations.DefaultInjectionStrategy; | |
| import org.apache.sling.models.annotations.Model; | |
| import javax.inject.Inject; | |
| @Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) | |
| public class TextfieldSampleComponentModel { | |
| @Inject | |
| private String yourname; | |
| @Inject | |
| private String yourcity; | |
| @Inject | |
| private String yourstate; | |
| public String getYourname() { | |
| return yourname; | |
| } | |
| public String getYourcity() { | |
| return yourcity; | |
| } | |
| public String getYourstate() { | |
| return yourstate; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //C:\aem-project\aemgeeks\ui.apps\src\main\content\jcr_root\apps\aemgeeks\components\AEMComponent\textfieldsamplecomponentwithdialogcrxd\textfieldsamplecomponentwithdialogcrxd.html | |
| <sly data-sly-use.userDetails="com.aemgeeks.core.models.TextfieldSampleComponentModel"> | |
| <h2>${userDetails.yourname}</h2> | |
| <h2>${userDetails.yourcity}</h2> | |
| <h2>${userDetails.yourstate}</h2> | |
| </sly> | |
| <sly data-sly-use.templates="core/wcm/components/commons/v1/templates.html" /> | |
| <sly data-sly-call="${templates.placeholder @ isEmpty = !userDetails.yourname}" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| C:\aem-project\aemgeeks\ui.apps\src\main\content\jcr_root\apps\aemgeeks\components\AEMComponent\textfieldsamplecomponentwithdialogcrxd\.content.xml | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" | |
| jcr:primaryType="cq:Component" | |
| jcr:title="Textfield Sample Component CRXD" | |
| componentGroup="AEM Geeks - Content"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| C:\aem-project\aemgeeks\ui.apps\src\main\content\jcr_root\apps\aemgeeks\components\AEMComponent\textfieldsamplecomponentwithdialogcrxd\_cq_dialog\.content.xml | |
| <?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="User Details" | |
| sling:resourceType="cq/gui/components/authoring/dialog"> | |
| <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"> | |
| <yourname | |
| jcr:primaryType="nt:unstructured" | |
| sling:resourceType="granite/ui/components/coral/foundation/form/textfield" | |
| fieldLabel="Name" | |
| name="./yourname"/> | |
| <yourcity | |
| jcr:primaryType="nt:unstructured" | |
| sling:resourceType="granite/ui/components/coral/foundation/form/textfield" | |
| fieldLabel="City" | |
| name="./yourcity"/> | |
| <yourstate | |
| jcr:primaryType="nt:unstructured" | |
| sling:resourceType="granite/ui/components/coral/foundation/form/textfield" | |
| fieldLabel="State" | |
| name="./yourstate"/> | |
| </items> | |
| </column> | |
| </items> | |
| </content> | |
| </jcr:root> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment