Search code examples
xpageslotus-domino

Xpages: How to bind events to a button whose visibility is computed


I'm using Xpages and my button (which has simple events bound to it) will not fire when i put it inside a panel whose visible property is computed on page load.

How can I go about achieving this?

EDIT:

thought I should clarify. The div holding the button is rendered using: facesContext.getMessages().hasNext(). (this tests if the user has failed validation).

if i set rendered simply using rendered = true, the button and its code works just fine.

thanks


Solution

  • If div's property rendered is false then the complete tag doesn't get included in HTML sent to browser including all elements inside the tag. That's why your button is just not there and can't fire any event.

    Add style="display:none" to rendered div tag when your div tag has to be hidden.

    Example:

    <xp:panel
        id="panel1">
        <xp:this.attrs>
            <xp:attr
                name="style"
                value="display:none"
                rendered="#{javascript: ! facesContext.getMessages().hasNext()}">
            </xp:attr>
        </xp:this.attrs>
        <xp:button
            value="Test"
            id="button1">
        </xp:button>
    </xp:panel>
    

    renders an invisible div tag including the button if ! facesContext.getMessages().hasNext() is true

    <div id="view:_id1:panel1" style="display:none">
        <button class="xspButtonCommand" type="button" name="view:_id1:button1"
                id="view:_id1:button1">Test
        </button>
    </div>
    

    otherwise it's visible

    <div id="view:_id1:panel1">
        <button class="xspButtonCommand" type="button" name="view:_id1:button1"
                id="view:_id1:button1">Test
        </button>
    </div>
    

    In both cases button events can by executed.