Thursday, November 29, 2012

Adobe CQ5 How to prevent the author to type text in pathfield

Hello everybody, I want to start sharing my knowledge in CQ with this little and easy post. I will break the ice saying that Adobe CQ is an enterprise CMS that runs on a Java SE platform, which is built on standard technologies like JCR, the OSGi Framework and Apache Sling, but I will left the overview about CQ for another post and focus this one in our topic.

In CQ, the pathfield widget  is an input field designed to enter paths, providing path completion and server repository browsing capabilities via a browsing button located at the right side of the field. This widget is very useful to provide an easy way to get local links from the server content repository, or to select some kind of approved external links. The problem many times is that this browser mechanism can be skipped and the author may enter code manually, pointing to an arbitrary or non approved link. When you start developing in CQ (as with other languages) you may forget this kind of details, and in fact I did, but when you are reviewing code or fixing bugs they will became notorious. How to get rid of that? Setting editable as false will do the trick. See the code below,

<?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:Dialog"
    height="400"
    stateful="false"
    xtype="dialog">
    <items jcr:primaryType="cq:WidgetCollection">
        <tabs jcr:primaryType="cq:TabPanel">
            <items jcr:primaryType="cq:WidgetCollection">
                <tab
                    jcr:primaryType="cq:Widget" 
                    title="Search"
                    xtype="panel">
                    <items jcr:primaryType="cq:WidgetCollection">
                        <pathfield
                            jcr:primaryType="cq:Widget"
                            editable="{Boolean}false"
                            fieldLabel="Link Address"
                            name=".pathfield"      
                            xtype="pathfield"/>
                    </items>                
                </tab>
            </items>
        </tabs>
    </items>
</jcr:root>

Refer to the CQ Widgets API to get more information about the widget you are using.

2 comments:

  1. hehe, genau das habe ich gesucht :-)
    Danke
    Bernd A

    ReplyDelete
  2. Hallo Bernd, ich freue mich darĂ¼ber, dass dieser Eintrag dir helfen konnte :)

    Sehen uns Morgen!
    Alberto

    ReplyDelete