In visualforce, I am iterating through a wrapper class and for each iteration, a textbox is displayed. My code snippet is:

<apex:repeat value="{!comList}" var="com">
<b>{!com.comment.name} : </b><br/>
<apex:inputTextarea id="textbox" value="{!com.reply}" /><br/>

<apex:commandButton value="Reply" action="{!replytoComment}" reRender="repeatFrm">
    <apex:param name="commentId" value="{!com.comment.id}" assignTo="{!commentId}" />
    <apex:param name="replyText" assignTo="{!replyText}" value="{!com.reply}"/>


I want to send the user input which is entered in the inputText Box to the controller with the help of "param" called replyText. But when I am clicking on "Reply" command button, replyText param is showing null value.

replyText is of getter setter type.

If somebody had faced such a situation, please help.


Note: actually , this question has been answered before in another forum but the solution did not convinced me at all , i want to know if there are better solutions .

here is the proposed answer using <apex: variable>, but this solution does not meet my requirement is there any other solution without using <apex: variable>

           <!-- Iterating through the list called comList for displaying all existing comments -->
       <apex:repeat value="{!comList}" var="com">
                <apex:inputTextarea id="textbox1" value="{!com.reply}" /><br/>
                <apex:commandButton value="Reply" action="{!replytoComment}" reRender="repeatFrm">
                    <apex:param name="commentId" value="{!rowNum}" assignTo="{!commentId}" />
                <!-- Incrementing rowNum by 1 on each iteration -->
                <apex:variable var="rowNum" value="{!rowNum + 1}"/>
  • So, what other answer didn't convince you? – tobibeer Feb 21 '16 at 15:08
  • I have edited the question – Merabti Ibrahim Feb 21 '16 at 15:29

if comList is some inner class Foo, then you simply

  • Have a map in the Controller of commentIds to Foos
  • Your commandButton need only have one parameter:

    <apex:commandButton value="Reply" action="{!replytoComment}" reRender="repeatFrm">
     <apex:param name="commentId" value="{!com.comment.id}" assignTo="{!commentId}" />
  • Then, your actionmethod replytoComment uses the value in controller variable commentId to lookup in the map the corresponding row of Foos with the updated inputTextArea reply.

Remember, the commandButton will send to the controller all the updated fields in the form (or containing actionRegion if defined) so the inputTextAreas for all rows are transmitted into their corresponding Foos.

  • @MerabtiIbrahim cool, glad I could help – cropredy Feb 22 '16 at 21:21

Its doesnt work becouse your var for iteration was used just to render static page. If you want to submit new value entered from the user, you have to get it dynamically with javascript and send it to salesforce server.

Try to register your controller method as actionFunction:

    <apex:actionFunction name="saveReply" action="{!replytoComment}" rerender="repeatFrm" 
immediate="true" >
      <apex:param name="reply_text" value="" />

Then you just create some javascript function, where you grab text from inputField dynamically by ID and call "saveReply" with your text as argument.

function callSaveReply() {
   var text = document.getElementById(your_id).value;

Then you change you commandButton 'onClick' property to call this JS function instead of using property 'action'.

In controller method replyToComment you can access before DML statement text value by:

String partname = System.currentPageReference().getParameters().get('reply_text');
  • But it works perfectly with the id <apex:param name="commentId" value="{!com.comment.id}" assignTo="{!commentId}" /> , the id is passed to the controller but the text is not because as tobibeer said i am trying to assign many input to the same variable – Merabti Ibrahim Feb 21 '16 at 16:49
  • The id is passed becouse it contains value, which is rendered into apex:param value after page load. Try to populate reply field on comment in salesforce before page reload and put System.debug into controller method. It wont be null now. – Martin.Kona Feb 21 '16 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.