java - Problems regarding PrimeFaces partial process -


in application, have managed bean:

@managedbean(name = "mrbean") @requestscoped public class mrbean {       @managedproperty(value = "#{param.id}")     private long   commentableid;     private string comment;      @postconstruct     public void init() {         system.out.println("init " + commentableid);     }      public void postcomment() {         system.out.println("post comment " + commentableid);     }      public void like(boolean like) {         system.out.println("like " + commentableid);     }      // getters , setters  } 

problem 1:

on page viewing articles, have following box commenting.

<h:panelgrid columns="1">     <p:inputtextarea id="comment" value="#{mrbean.comment}" />      <p:commandbutton actionlistener="#{mrbean.postcomment}" value="post">         <f:param name="id"  value="#{viewcommentable.commentableid}" />     </p:commandbutton> </h:panelgrid> 

everything works fine above code. however, since postcomment() function requires comment property, tried put in process='comment' above p:commandbutton. @ point, whenever click post button, see init [commentableid] on console. however, never see post comment [commentableid]. in other words, listener method postcomment() never called though bean created correctly.

problem 2:

on same page, have following toggle buttons liking/disliking article.

<h:inputhidden id="commentableid" value="#{mrbean.commentableid}" />  <p:selectbooleanbutton id="like" value="#{viewcommentable.commentable.liked}" onlabel="liked" offlabel="like" >     <p:ajax process="like dislike commentableid" listener="#{mrbean.like(viewcommentable.commentable.liked)}" /> </p:selectbooleanbutton>  <p:selectbooleanbutton id="dislike" value="#{viewcommentable.commentable.disliked}" onlabel="liked" offlabel="like" >     <p:ajax process="like dislike commentableid" listener="#{mrbean.dislike(viewcommentable.commentable.disliked)}" /> </p:selectbooleanbutton> 

these buttons working fine. however, observed quite weird. when click button, on console saw these lines:

init null [commentableid] 

somehow, property commentableid not available in init() function later on in like() function.

i'd grateful if give me explanation above 2 problems.

best regards,

i've realised didn't use process attribute correctly. in order process partially, in <p:commandbutton>, need ids of components want process as @this process button itself. besides, problem didn't use correct syntax process attribute. ids should separated comma not space. following snippet should work:

<p:commandbutton process="@this, comment" actionlistener="#{mrbean.postcomment}" value="post">     <f:param name="id" value="#{viewcommentable.commentableid}" /> </p:commandbutton>  <p:selectbooleanbutton id="like" value="#{viewcommentable.commentable.liked}" onlabel="liked" offlabel="like" >     <p:ajax process="like, dislike, commentableid" listener="#{mrbean.like(viewcommentable.commentable.liked)}" /> </p:selectbooleanbutton> 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -