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:
- you need send ajax call only when enter key pressed, need bind
<h:inputtext>
tag'sonkeydown
attribute javascript code that; <f:ajax>
attributerender
, notrendered
;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
Post a Comment