davidx1
davidx1

Reputation: 3673

In CQ5, why does the 'checkbox' xtype not work? But a 'selection' xtype and a 'checkbox' type is needed to create a working checkbox in a dialog?

So there is an xtype called 'checkbox'. When I apply this to a cq:widget, the check box shows up in the dialog but the information doesn't get passed into the JSP. I was trying to make a checkbox that controls the input type of a <input> html tag.

After looking around, I found that the proper way to create a checkbox is with a xtype set as 'selection' and type set as 'checkbox' and it works.The only thing I changed is the type and the xtype.

Here's how I'm using it in the JSP

    <%final boolean checked= properties.get("checkbox", false);
    request.setAttribute("checked", checked);%>

    <input type = <c:out value="${checked?'text':'password'}"/>

I was wondering what's the difference between the two approaches, why doesn't the first approach work?

EDIT: Or rather, how is the xtype 'checkbox' suppose to be used? What is it actually for?

Upvotes: 2

Views: 983

Answers (1)

Shawn
Shawn

Reputation: 9402

Ultimately the 'checkbox' xtype doesn't work because it is designed in a way that doesn't preserve the state on its own, as @Emin commented.

When a user loads a component that uses a 'checkbox' xtype in the dialog, the first load of that page the underlying JCR node does not have any dialog properties stored for that checkbox because it hasn't been author-configured yet. Then, if the author checks the box to configure it and saves the dialog, the form submission in the dialog will include the selection and the property will be saved the the repository as having been checked.

But then if the author later changes things and unchecks the box, the dialog form submission won't include anything about this checkbox, so the underlying property in the JCR repository isn't touched--it remains as-is, which indicates the box as having been checked. So when the author re-loads the page, the box is still checked (not what the author wanted).

The xtype of 'selection' saves you from having to deal with this.

Upvotes: 2

Related Questions