3

How can I make the mainDiv clickable and invoke a backing bean action method?

<h:panelGroup layout="block" id="mainDiv">
    <h:panelGroup layout="block" style="float:left;">
        <h:outputText value="#{messageItem.sendBy.registerName}"/>
    </h:panelGroup>
    <h:panelGroup layout="block" style="float:right;">
        <h:outputText value="#{messageItem.sendDate}">
            <f:convertDateTime pattern="HH:mm"/>
        </h:outputText>
    </h:panelGroup>
</h:panelGroup>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
F25rT
  • 114
  • 1
  • 10

2 Answers2

4

The simplest way would be to wrap its contents in a <h:commandLink>, if necessary with <f:ajax>. Use CSS display:block to let the link span the entire div.

<h:panelGroup layout="block" id="mainDiv">
    <h:commandLink action="#{bean.action}" style="display:block;">
        <f:ajax />
        ...
    </h:commandLink>
</h:panelGroup>

Or, given your question history you're using PrimeFaces, you can also use <p:remoteCommand>.

<h:panelGroup layout="block" id="mainDiv" onclick="functionName()">
    ...
</h:panelGroup>
<p:remoteCommand name="functionName" action="#{bean.action}" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

You can use f:ajax on panelGroup

<h:panelGroup>
    <f:ajax event="click" listener="#{adminPanel.test}"></f:ajax>
    xxx
</h:panelGroup>

resulting html :

<span id="j_idt169" onclick="mojarra.ab(this,event,'click',0,0)">
    xxx
</span>
Ced
  • 15,847
  • 14
  • 87
  • 146