selectManyCheckbox in ui:included dialog not reset

UI Components for JSF
Post Reply
healeyb
Posts: 365
Joined: 07 Apr 2010, 16:05

19 Jan 2011, 16:43

I've got a commandLink which fires a p:dialog which contains a
selectManyCheckbox. I select one of the checkboxes, and hit a
cancel button within the dialog. The cancel button hide()'s the dialog.

I then click the commandLink again to show() the dialog. The checkbox
previously selected is still selected. Same with the close function. The
thing is that the commandLink has an action routine which resets the
value= property of the selectManyCheckbox (resetTypes is a
Collection<String> - in the action routine I set it to null).

I've tried using an actionListener but same result. When I click the link
to open the dialog I can see the resetDialog2() action method firing
before the selectManyCheckbox getter, so it's almost as if the dialog is
cacheing the content that is displayed.

The commandLink has update= for the dialog component and has
immediate=true. I've found that without immediate=true the
selectManyCheckbox issues a required=true validation error upon first
rendering of the dialog. In other cases where I'm just displaying data
in the dialog then without immediate=true the data is not available.

This is a pretty minor issue really but if anyone can see where I'm going
wrong I'd appreciate knowing about it. [I've also noticed that the action
routine on the commandLink won't fire unless immediate="true" is
specified].

Code: Select all

<h:form prependId="false">
...
                <p:column style="text-align: center">
                    <p:commandLink
                        action="#{emmView.resetDialog2}"
                        update="dialog2"
                        immediate="true"
                        oncomplete="dlg2.show(); return false;">
                        <h:graphicImage library="images" name="icons/trash_16x16.gif"
                                        title="#{msgs.deleteHeader}"/>
                        <f:setPropertyActionListener target="#{emmView.dialogMember}"
                                                     value="#{tm}"/>
                    </p:commandLink>
                </p:column>
            </p:dataTable>
   <ui:include src="dialog.xhtml"/>
</h:form>
dialog.xhtml

Code: Select all

<ui:composition ...>
<p:dialog id=dialog2" header="#{msgs.memberDetailsText}" widgetVar="dlg2" closeOnEscape="true" minWidth="400">
            <h:panelGrid columns="2"
                         rendered=" ... condition ...">
                <h:selectManyCheckbox id="type" value="#{emmView.resetTypes}"
                                      layout="lineDirection"
                                      required="true" requiredMessage="#{msgs.registerGenderRequired}">
                    <f:selectItem .../>
                    <f:selectItem ..."/>
                </h:selectManyCheckbox>
                <h:message for="type" styleClass="errors"/>
                <br/>
            </h:panelGrid>
            <p:commandButton value=" #{msgs.okText} "
                             action="#{emmView.resetMemberState(emmView.dialogMember)}"
                             update="outputdt"
                             oncomplete="dlg2.hide(); return false;"/>
            <p:commandButton value="#{msgs.cancelButtonLabel}"
                             update="outputdt"
                             oncomplete="dlg2.hide(); return false;"/>
    </p:dialog>
</ui:composition>
Thanks,
Brendan.

Mojarra 2.0.4
PF RC-2.2
Glassfish 3.0.1

shuta
Posts: 15
Joined: 25 Dec 2010, 19:20

19 Jan 2011, 23:47

Could you try one thing? Put your checkboxes into a separate h:panelGroup or h:form that is nested into the p:dialog, assign an ID to it and then update this nested component instead of directly updating the dialog. I had such problems with the ConfirmDialog (you are not supposed to update a ConfirmDialog), and while I haven't had any issues yet with updating regular dialogs, maybe you should give this a try.

(Do not attempt to nest h:form components... i.e. if you have got a top-level form somewhere, do not add a direct or indirect child form anywhere. This will break things, since nested forms are not valid HTML)

healeyb
Posts: 365
Joined: 07 Apr 2010, 16:05

20 Jan 2011, 02:10

Thanks for the good suggestion - at various times today I've had the
dialog in it's own form, with the form nested inside the dialog, outside,
the dialog, in the main form, I've had panelGroups all over the place. Good
news though, I figured it out eventually - the pattern required is as per
my original post but eliminate the action= routine on the p:commandLink
and specify p:dialog (at least) like this:

<p:dialog id="dlg" closeListener="#{bean.cl} onCloseUpdate="dlg" ...>

Where the closeListener is void cl(CloseEvent ce) and you reset the
selectManyCheckbox value= in this method.

What caused me problems was that my glassfish server log view in
netbeans froze, so I was expecting to see log output from various methods
which was actually being produced but I could seeing nothing in the log.
This was a sufficiently powerful distraction to prevent me from seeing
what was really going on in the browser window.

Also the closeListener takes a CloseEvent parameter and I'd got it into
my head that it took an ActionEvent (do we really need all these different
types of parameters on listeners? just a thought).

Regards,
Brendan.
Last edited by healeyb on 20 Jan 2011, 14:09, edited 1 time in total.

healeyb
Posts: 365
Joined: 07 Apr 2010, 16:05

20 Jan 2011, 06:11

shuta - I'd just got a working solution seconds before I read your reply,
but will test your suggestions tomorrow. My present scenario involves a
dialog updating itself via ajax - somehow it doesn't feel right. I'm sure
that it would be helpful to have a "design pattern" for this, if that's not
too grand a term, and I'll continue tomorrow.

Cheers,
Brendan.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests