jsf - How to use ajax update content but without submit button -


i have jsf code this. when user finish input name , comment , press 'enter', content can show in 'content........' part.

<h:form id="all_comments">     content........ </h:form> <h:form id="submit_comment">     <h:inputtext id="name_box" value="#{managedbean.user}"/>     <h:inputtext id="content_box" value="#{managedbean.comment}" /> </h:form> 

i want use ajax finish it, , try this:

<h:form id="all_comments">     content........ </h:form> <h:form id="submit_comment">     <h:inputtext id="name_box" value="#{managedbean.user}"/>     <h:inputtext id="content_box" value="#{managedbean.content}">         <f:ajax event="keydown"                 listener="#{managedbean.addcomment}"                 execute="comment_name_box comment_content_box"                 rendered=":all_comments" />     </h:inputtext> </h:form> 

but failed, can achieve when user press 'enter', data processed managedbean, using ajax update page.

you've got points missing:

  1. you need send ajax call only when enter key pressed, need bind <h:inputtext> tag's onkeydown attribute javascript code that;
  2. <f:ajax> attribute render, not rendered;
  3. submit_comment form should rerendered well, new data presented user, , placeholders have refreshed in ajax listener well.

here solution when want submit second form on event:

<h:form id="all_comments">     content........ </h:form> <h:form id="submit_comment">     <h:inputtext id="name_box" value="#{managedbean.user}"/>     <h:inputtext id="content_box" value="#{managedbean.content}"                  onkeydown="return (event.keycode == 13);">         <f:ajax event="keydown"                 listener="#{managedbean.addcomment}"                 execute="@form"                 render="@form :all_comments" />     </h:inputtext> </h:form> 

with

public void addcomment(ajaxbehaviorevent abe) {     comments.add(new comment(user, content));     user = "";     content = ""; } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -