2012-05-07 57 views
16

我試圖在編輯時在組件對話框上選中默認複選框。以下是該領域的屬性:獲取默認選中CQ5中的複選框

jcr:primaryType: widget 
checked: true (boolean) *Documentation says this determines default checked status 
type: checkbox (string) *read this as a fix to making checkbox selections stick 
xtype: selection (string) 
name: ./foo (string) 
fieldValue: true (string) 

回答

17

是的,它看起來像the documentation有點靠不住。我做了一些嘗試,而這種性質的組合爲我的作品:

defaultValue (String) true 
fieldLabel (String) Foo Mode 
inputValue (String) false 
jcr:primaryType (Name) cq:Widget 
name (String) ./foomode 
type (String) checkbox 
xtype (String) selection 

默認值屬性似乎是關鍵。

你有cq:你的主要類型的小部件,而不是小部件,你不?

+2

非常感謝。我不會自己設計這種組合。來吧,Adobe,更好地管理你的文檔! –

+0

我遇到了完全相同的問題,並由於不準確的CQ文檔而變得更糟。更深入地看,上述組合將成功地在對話框上呈現一個「檢查」複選框,但不會導致設置表示該複選框元素的底層JCR屬性,即沒有爲該複選框預先創建的./foomode屬性,它只會在用戶訪問對話框後創建,並且即使沒有進行任何更改也會點擊「確定」按鈕。 –

+0

在POST請求創建它們之前,不會創建節點屬性。另外,記住一個複選框不會被提交,除非它被選中。這不是CQ的功能,它在HTML規範中並由瀏覽器實現。如果要創建節點屬性,而不管該複選框是否已選中,請使用SlingPostServlet的@UseDefaultWhenMissing後綴。請參閱Apache Sling文檔:https://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#usedefaultwhenmissing。 – nateyolles

5

爲了這個保存爲一個布爾...

<nodeName 
jcr:primaryType="cq:Widget" 
fieldLabel="check this nodename" 
name="./nodeName" 
defaultValue="{Boolean}false" 
type="checkbox" 
xtype="selection" /> 

<nodeNameHint 
    jcr:primaryType="cq:Widget" 
    ignoreData="{Boolean}true" 
    name="./[email protected]" 
    value="Boolean" 
    xtype="hidden"/> 
1

要設置複選框選中與和默認值保存屬性爲布爾屬性類型在JCR(而不是字符串) ,使用下面的經典UI設置:

<myCheckbox 
    jcr:primaryType="cq:Widget" 
    fieldLabel="My Checkbox" 
    name="./myCheckbox" 
    value="true" 
    defaultValue="true" 
    checkboxBoolTypeHint="{Boolean}true" 
    type="checkbox" 
    xtype="selection"/> 

或使用花崗岩觸摸UI進行如下設置:

<myCheckbox 
    jcr:primaryType="nt:unstructured" 
    sling:resourceType="granite/ui/components/foundation/form/checkbox" 
    text="My Checkbox" 
    name="./myCheckbox" 
    value="true" 
    checked="true"/> 
<myCheckboxType 
    jcr:primaryType="nt:unstructured" 
    sling:resourceType="granite/ui/components/foundation/form/hidden" 
    name="./[email protected]" 
    value="Boolean"/> 

http://www.nateyolles.com/blog/2015/11/aem-checkboxes-using-sling-post-servlet有一個詳細的書面和演示。