0

I am using following code and trying to make each row clickable and set some event of top of that.

<table width="100%" class="TableSpace">

<ui:repeat var="damageinfo"
                            value="#{DamageDetails2.damageInfoAll}" varStatus="status">
    <h:commandLink>
        <tr class="row1 lineBorder" onclick="alert('Hello')">
            <td height="40">
                <h:outputText
                        value="#{damageinfo.damageID}" styleClass="LabelClass">
                </h:outputText>
            </td>
            <td height="40">
                <h:outputText
                        value="#{damageinfo.damageName}" styleClass="valueClass">
                </h:outputText>
            </td>
        </tr>
        <f:setPropertyActionListener target="#{carDetails.rootImage}"
                                    value="#{carDetails.carUrl2}" />
        <f:setPropertyActionListener target="#{carDetails.view}"
                                    value="#{carDetails.viewDetails['carUrl2']}" />
        <f:ajax event="action" render="ViewId" />
    </h:commandLink>
</ui:repeat>

</table>

But it does not work. How is this caused and how can I solve it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
zytham
  • 613
  • 1
  • 12
  • 27
  • This might help; http://stackoverflow.com/questions/3909267/differences-between-action-and-actionlistener AND http://mkblog.exadel.com/2010/04/learning-jsf-2-ajax-in-jsf-using-fajax-tag/ – mhan Jul 16 '12 at 13:13

1 Answers1

1

This generates invalid HTML. It's illegal to have an <a> element around the <tr>. The browser behaviour is unspecified. Depending on the lenientness of the webbrowser make/version used, it might work, or it might not work, or it might not work the way you intend. As JSF ultimately just generates HTML, it really can't do any magic to make it to work the way you intend.

Either put a JS onclick handler in the <tr> element or put <h:commandLink> inside the <td>, or use a 3rd party component library like PrimeFaces which allows row selection, see also this showcase example.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • is not working inside tag .if i will use onclick method whether it will reflect the change from bean on same page without refresh ?? – zytham Jul 16 '12 at 14:02
  • With the code given so far there are too many possible causes for the `` not working inside the ``. Refer this answer then: http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183 As to the `onclick`, just let it invoke a by CSS hidden `` inside the ``. – BalusC Jul 16 '12 at 14:04