无法通过在apexclass上单击它来获取Commandbutton的值

时间:2014-08-11 12:33:39

标签: salesforce apex

VF代码:

<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类代码:

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 ));

}

大家好, 我想通过使用重复功能显示按钮的值。以上是我的代码,我无法分别显示按钮值。

提前致谢。

1 个答案:

答案 0 :(得分:1)

在控制器中使用Name attribute value

 ButtonNum = apexpages.currentpage().getparameters().get('paramValue');

OR

你可以使用apex的assignTo属性:param它在控制器中给出值:

<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课程:

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 ));    
 }
}

希望它可以帮到你