0

I have a number in an input text that I want to pass on to the controller:

    <div class="divTable">
        <div class="divRow">
            <div class="cellOne">
                <label>Number of participants</label>
            </div>
            <div class="cellTwo">
                <apex:inputText value="{!integerNumberParticipants}"/>
                <apex:commandButton value="Add Row" action="{!addRows}">
                    <apex:param name="addCount" value="{!integerNumberParticipants}" assignTo="{!addCount}"/>
                </apex:commandButton>
            </div>
        </div>
    </div>

and the function where it gets processed:

public void addRows(){
    for (Integer idx=0; idx<addCount; idx++){
            wrappers.add(new ParticipantsWrapper(nextIdent++, selectedRecordId));
    }
}

The code functions when I pass on value="{!1}", and I have integerNumberParticipants declared as a { get; set; } and initiated in the controller. So what is the problem here?

Thank you for your help!

1

You don't need that <apex:param> tag at all. The <apex:inputText> tag automatically binds it to a variable in the controller.

<apex:inputText value="{!addCount}"/>
<apex:commandButton value="Add Row" action="{!addRows}"/>

As soon as the button is hit, the entire form is submitted to the server, including the field. The value of the field is bound to the addCount variable in the controller for you to process.

Also, use this guy to allow for automatically handling the data conversion from string to integer.

<apex:input type="number" value="{!addCount}"/>

Otherwise, you'll have to assign the value to a string in the controller and use server side code (integer.valueOf(StringToConvertToInteger)).

2
  • Thank you very much, that works really nicely! Just to add, I had to put docType="html-5.0" into apex:page to make it work. – Andrea Voggenreiter Apr 26 '17 at 16:34
  • That makes sense if you're using apex:input as that is an HTML 5 tag. Glad it works for you :) – gNerb Apr 26 '17 at 19:53

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.