Reputation: 185
VF code:
<apex:repeat value="{!strings}" var="stringer" id="theRepeat">
<apex:CommandButton value="{!stringer}" id="theValue"style="padding:10px;spacing:10px" action="{!repeatFunction}">
<apex:param name="paramValue" value="{!stringer}"/>
</apex:commandButton>
</apex:repeat>
Apex Class Code:
public String[] getStrings() {
return new String[]{'ONE','TWO','THREE'};
}
public String ButtonNum {get;set;}
public void repeatFunction() {
ButtonNum = apexpages.currentpage().getparameters().get('stringer');
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.Info,'num'+ButtonNum ));
}
Hi Everyone, I want to display the value of the button by using repeat function. Above is my code and i'm unable to display the button values respectively.
Thanks in advance.
Upvotes: 0
Views: 360
Reputation: 1639
Use Name attribute value
in the controller
ButtonNum = apexpages.currentpage().getparameters().get('paramValue');
OR
You can use assignTo
attribute of apex:param it gives value in controller:
<apex:page controller="test">
<apex:outputPanel id="msg">
<apex:messages />
</apex:outputPanel>
<apex:form >
<apex:repeat value="{!strings}" var="stringer">
<apex:commandButton value="{!stringer}" id="theValue" action="{!repeatFunction}" reRender="msg">
<apex:param name="paramValue" value="{!stringer}" assignTo="{!ButtonNum}"/>
</apex:commandButton>
</apex:repeat>
</apex:form>
</apex:page>
Apex Class :
public class test
{
public String[] getStrings()
{
return new String[]{'ONE','TWO','THREE'};
}
public String ButtonNum {get;set;}
public void repeatFunction()
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.Info,'num :'+ButtonNum ));
}
}
Hope it helps you
Upvotes: 1