You need to sign in to do that
Don't have an account?
apex:commandButton never calls it's action
So this is stumping me, not my first visualforce component, but I just can't figure out why my save button never calls the saveComment action from the controller.
I added a System.asser(false); statement to make it throw an exception no matter what, just to be clear the method is never called.
When I press a comment button on a chatter post it renders the comment section as expected, but when I press the save button nothing happens (if I remove the rerender option the page refreshes but does nothing else). No exceptions in the log, and no matter what I should get a failed assertion if the method is ever called.
Help?
Without further ado, the offending code:
VF Page for a chatter-enabled custom object:
<apex:page standardController="itil_b__Incident__c" extensions="ChatterController"> <apex:form > <c:ChatterBlock subject="{!itil_b__Incident__c}" /> </apex:form> </apex:page>
ChatterBlock component:
<apex:component controller="ComponentChatterBlock" allowDML="true" selfClosing="true"> <apex:attribute name="subject" type="sObject" required="true" assignTo="{!subject}" description="The sObject to show a chatter feed for." /> <apex:outputPanel rendered="{!IF(inited = false,'true','false')}"> {!init} </apex:outputPanel> <!-- Start of Content --> <apex:outputPanel style="width: 50%; "> <apex:outputPanel rendered="{!feed.posts.size > 0}" id="feedData"> <apex:dataTable value="{!feed.posts}" var="post" rules="All" border="2"> <apex:column > {!post.posterName.name}<br /> at {!post.formatedCreatedDate} </apex:column> <apex:column > <!-- Post body, for text and link posts --> <apex:outputField rendered="{!IF(post.postType = 'TextPost' || post.postType = 'LinkPost','true','false')}" value="{!post.fpost.body}" /> <!-- Link URL and title for link posts --> <apex:outputLink rendered="{!IF(post.postType = 'LinkPost','true','false')}" value="{!post.fpost.LinkURL}"> <br /> <apex:outputField value="{!post.fpost.title}" /> </apex:outputLink> <!-- Single history post --> <apex:outputText rendered="{!IF(post.fchanges.size = 1,'true','false')}" value="{!post.firstChange.fieldLabel} changed from {!post.firstChange.oldValue} to {!post.firstChange.newValue}" /> <!-- Multiple History posts --> <apex:outputPanel rendered="{!IF(post.fchanges.size > 1,'true','false')}"> <ul> <apex:repeat value="{!post.fchanges}" var="change"> <li>{!change.fieldLabel} changed from {!change.oldValue} to {!change.newValue} </li> </apex:repeat> </ul> </apex:outputPanel> </apex:column> <apex:column > <apex:commandButton value="Comment" rerender="{!$Component.newComment}" action="{!newComment}" > <apex:param name="commentParentId" value="{!post.postId}" assignTo="{!newComment.parentId}" /> </apex:commandButton> </apex:column> </apex:dataTable> <apex:outputPanel id="newComment"> <apex:pageMessages /> CID: {!newComment.FeedItemId} <apex:outputPanel rendered="{!IF(renderComment = true,'true','false')}"> <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton action="{!cancelComment}" value="Cancel" /> <apex:commandButton value="{!saveComment}" value="Save" rerender="feedData"/> </apex:pageBlockButtons> <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:inputField value="{!newComment.commentBody}" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:outputPanel> </apex:outputPanel> </apex:outputPanel> <apex:outputPanel rendered="{!feed.posts.size < 1}"> There are no posts for this object. </apex:outputPanel> </apex:outputPanel> </apex:component>
And my page controller:
public with sharing class ComponentChatterBlock { public boolean inited {get; set;} public sObject subject {get; set;} public Chatter feed {get; set;} public FeedComment newComment {get; set;} public boolean renderComment {get; set;} public ComponentChatterBlock(){ inited = false; } public void getInit(){ System.assert(inited == false); if(inited == false) { feed = new Chatter(subject, true); inited = true; } } public PageReference newComment(){ newComment = new FeedComment(); renderComment = true; System.debug('New comment called: '+newComment); return null; } public PageReference cancelComment(){ System.assert(false); newComment = null; return null; } public PageReference saveComment(){ System.assert(false); insert newComment; return Page.IncidentDetail; } }
Sometimes it's good to just have another pair of eyes look at your code....
Your Command button definition has two Value= attributes and no Action= attribute.
I think this might have something to do with it! :-)
Best, Steve.
All Answers
Sometimes it's good to just have another pair of eyes look at your code....
Your Command button definition has two Value= attributes and no Action= attribute.
I think this might have something to do with it! :-)
Best, Steve.
yaa right u need to give the command button as
**bleep**, thats what I get for coding while tired.
Thanks for catching that!