5 Replies Latest reply on Feb 16, 2013 3:06 AM by YongWu

    How to disable/enable a dialog dynamically?

    YongWu

      I use <cq:include> to include a component, which has a dialog. I want to disable the dialog dynamcally based on some condition, i.e. not allow the author to open the dialog when he double-click on the component. How can I achieve that easily?

       

      Thanks,

        • 1. Re: How to disable/enable a dialog dynamically?
          splram Level 1

          You might have thought through this, but posting this response because sometimes things can be done in a simpler way but we end up thinking it being a complex thing.

           

          You can try to do <cq:include> of the component only if the condition is met, if the condition is not met render some text that indicates it is a read-only kind of component (the stuff that you want to show if component is not editable, may be a div with a different border) where user cannot double-click at all.

          • 2. Re: How to disable/enable a dialog dynamically?
            YongWu Level 1

            Thanks for the reply. But I still want to use <cq:include> even the condition isn't met. Becasue in the component I want to use the CQ defined objects like slingrequest, currentResource, etc. I am just wonderring if there is some options to turn off the dialog programatically, but still keep other features.

            • 3. Re: How to disable/enable a dialog dynamically?
              YongWu Level 1

              Anyone has solution to this?

              • 4. Re: How to disable/enable a dialog dynamically?
                msulliva Level 2

                There are examples of this in the CQ code somewhere, but typically you can used the WCMMode and temporarily disable it for the cq include and then return it to the state it was in.

                 

                Page Import:

                 

                com.day.cq.wcm.api.WCMMode

                 

                Store the current WCMMode (probably optional):

                 

                WCMMode mode = WCMMode.fromRequest(request);

                 

                Disable the WCMMode:

                 

                WCMMode disabled = WCMMode.DISABLED.toRequest(request);

                 

                Perform <cq:include>

                 

                Return WCMMode:

                 

                disabled.toRequest(request);

                 

                If there is any chance of an exception with the include, it may be valuable to perform the include in a try / catch and then put the "disabled.toRequest(request)" in a finally statement.

                 

                <%@page import="com.day.cq.wcm.api.WCMMode" %><%

                %><%@include file="/libs/foundation/global.jsp"%><%

                   

                WCMMode disabled = WCMMode.DISABLED.toRequest(request);

                 

                try {

                   

                    %><cq:include /><%

                   

                } finally {

                    disabled.toRequest(request);

                }

                1 person found this helpful
                • 5. Re: How to disable/enable a dialog dynamically?
                  YongWu Level 1

                  Thanks,  msulliva. I think this is what I am looking for.