One of the challenges of XPages is figuring out what controls actually do. In a prior post, I wrote about using a dialog to return values to the XPage. It never occurred to me to use dialogContent and dialogButtonBar in the dialog. Today, when I was creating another dialog, I used the palette to find the dialog control and noticed those two. I wondered what they did, since, in my example, I hadn’t used them and my dialog displayed easily.
I checked the documentation, which really doesn’t help, stating simply that the dialogButtonBar “Contains buttons in a dialog.” That sure doesn’t tell me why I should use it instead of just putting my controls right into the dialog.
So, I did a little test.
<?xml version="1.0" encoding="UTF-8"?> <xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex"> <xp:link escape="true" text="Add a Linkage" id="addLinkageLink"> <xp:image url="/plus.png" id="addLinkageImage" style="position:relative;left:2px;top:-2px;margin-right:5px;"> </xp:image> <xp:eventHandler event="onclick" submit="false"> <xp:this.script><![CDATA[XSP.openDialog('#{id:linkageDialog}');]]></xp:this.script> </xp:eventHandler> </xp:link> <xp:link escape="true" text="Add without content control" id="link1"> <xp:image url="/plus.png" id="image1" style="position:relative;left:2px;top:-2px;margin-right:5px;"> </xp:image> <xp:eventHandler event="onclick" submit="false"> <xp:this.script><![CDATA[XSP.openDialog('#{id:contentFreeDialog}');]]></xp:this.script> </xp:eventHandler> </xp:link> <xp:br></xp:br> <xe:dialog id="linkageDialog" title="Add linkage"> <xe:dialogContent id="dialogContent1"> <xp:label value="Label" id="label1"></xp:label> <xp:inputText id="inputText1"></xp:inputText> </xe:dialogContent> <xe:dialogButtonBar id="dialogButtonBar1"> <xp:button value="OK" id="button1"></xp:button> <xp:button value="Cancel" id="button3"> <xp:eventHandler event="onclick" submit="false"> <xp:this.script><![CDATA[XSP.closeDialog('#{id:linkageDialog}');]]></xp:this.script> </xp:eventHandler> </xp:button> </xe:dialogButtonBar> </xe:dialog> <xe:dialog id="contentFreeDialog"> <xp:label value="Label" id="label2"></xp:label> <xp:inputText id="inputText2"></xp:inputText> <xp:button value="OK" id="button2"></xp:button> <xp:button value="Cancel" id="button4"> <xp:eventHandler event="onclick" submit="false"> <xp:this.script><![CDATA[XSP.closeDialog('#{id:contentFreeDialog}');]]></xp:this.script> </xp:eventHandler> </xp:button> </xe:dialog> </xp:view>
The dialog using the dialogContent and dialogButtonBar controls looks far nicer. I did put the title on the one without those sub-controls in order to make the disparity even more stark. When using the sub-controls, the placement of the content and the buttons is handled for you, without requiring the additional formatting I had to do in the prior post using a dialog. So, here’s the ugly one, which doesn’t use the sub-controls and will require some formatting:
And here’s the pretty one, with the sub-controls in use:
So, using the dialogContent and dialogButtonBar controls makes your life easier and your users happier.