Search code examples
jsfrichfaces

Hotkey enter on commandButton JSF and Richfaces


i want a button to be executed when pressing enter, but somehow that doesn't work:

<f:view>
 <h:body>
   <h1>#{bv.title}</h1>
   <h2>#{bv.version}</h2>
   <h:panelGrid columns="2">
    <h:form id="searchForm">
......
<f:facet name="footer">
       <h:panelGroup style="display:block; text-align:left">
        <h:commandButton style="font-size: large;" id="create" value="#{bv.buttonCreate}" action="#{search.create}" />
        <h:commandButton style="font-size: large;" id="clear" value="#{bv.buttonReset}" action="#{search.clear}" immediate="true" /><br/>
        <h:commandButton style="font-size: large;" id="pdf" rendered="#{search.jpgRendered}" immediate="true" action="#{search.openPDF}" value="Drucken als PDF" />
        <rich:hotKey key="return"
                         selector="#searchForm"
                         handler="#{rich:element('searchForm:create')}.click();
                         event.stopPropagation();event.preventDefault();
                         return false;"/>
       </h:panelGroup>
      </f:facet>

Any idea why this doesn't work?

Thx!


Solution

  • The handler attribute should be a name of a JS function not a function itself (docs). That is if you're using RF3, RF4 has no handler attribute.

    Edit: for RF4 there are onkeyup and onkeydown attributes that work the same (docs), but you can choose when should the action fire.