Tyrelius
Tyrelius

Reputation: 41

AEM/CQ Component Doesn't Render after Update

So, I have made an update to a component that I had previously built. The component used to just render a button that would like to another page. However, I needed to add functionality so that it could display static text instead of a button. So I added a radio button group where you could select between button and static text.

However, after doing the update, anyplace the component has already been used on a page, it doesn't render the button anymore. So I changed it up so that the default radio option would be button. Now, when I drop a new component on the page, it defaults to button. But existing components don't default to anything until I double click them and click OK; no other changes are needed, just need to open and close the component, then it seems to see the defaults.

My question is, how do I make is so that anyplace the component is already deployed will use the default option radio button, and render accordingly, without having to be opened and closed? Or is there a way to get AEM to refresh every component on all the pages so that it will see and use the new radio button, which will default them to button?

I would rather not add code to the JSP that tells it "else if nothing is selected, use button".

Upvotes: 1

Views: 2171

Answers (2)

Tyrelius
Tyrelius

Reputation: 41

What I ended up doing with this problem was, in the code where I choose to do different things based on the value of the radio button, I used if statements. I then copied the if for the value I want to be the default into the else.

Upvotes: 0

CptBartender
CptBartender

Reputation: 1220

Within the dialog definition you can only specify the dialog's default value. When you drag and drop the component, the dialog does not even exist yet. When you open it, it fills with the default values provided by you in the dialog definition, and then, once you close it, POSTs them to the JCR so that you can see the effect.

To actually initialize the component with default values on creation you need to create a proper content template. For more info, see this page

Edit: Unfortunately, there is no easy way to add the default content to already existing components, since the component is past it's initialization state. The way I go around this is, I create a Groovy script that puts the required (in this case, default) values into the JCR and run it using Groovy Console. Once you install it, go to /etc/groovyconsole.html and run a script that goes something like this:

session.refresh(false)
def query = session.getWorkspace().getQueryManager().createQuery(
    "SELECT * FROM [nt:unstructured] AS s " +
    "WHERE s.[sling:resourceType] = '/path/to/my/component' " +
    "AND s.[myProperty] IS NULL",javax.jcr.query.Query.JCR_SQL2)
query.execute().getNodes().each { jcrNode ->
    println "set value for $jcrNode"
    jcrNode.setProperty('myProperty', myValue)
}
//uncomment if you're happy with the list of applicable nodes printed by the script
//session.save()

It's not the prettiest and safest, but it should work. I hope I did not make any typos in there.

Upvotes: 1

Related Questions