在CQ5中获取默认选中的复选框

时间:2012-05-07 14:07:10

标签: 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)

3 个答案:

答案 0 :(得分: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

defaultValue属性似乎是密钥。

你有主要类型的cq:Widget,而不是widget,不是吗?

答案 1 :(得分: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="./nodeName@TypeHint"
  value="Boolean"
  xtype="hidden"/>

答案 2 :(得分:3)

要设置复选框,默认值为checked 将属性保存为JCR中的布尔属性类型(而不是字符串),请使用以下经典UI设置:

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

或者在Granite Touch 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="./myCheckbox@TypeHint"
    value="Boolean"/>

http://www.nateyolles.com/blog/2015/11/aem-checkboxes-using-sling-post-servlet有一个详细的写作和演示。