隐藏输入Visualforce Pages中单选按钮选择的字段

时间:2013-08-12 11:22:14

标签: radio-button apex-code visualforce input-field

我有一个输入字段和两个单选按钮。

我想隐藏单选按钮上的输入字段。

有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:2)

一种非常标准的方法

Visual Force Page

apex:page standardController =" contact"扩展=" radioActionPageCtrl">

<apex:form >

  <apex:selectRadio id="valSelector" value="{!optSelected}">
   <apex:SelectOptions value="{!radioValues}"/>
   <apex:actionSupport event="onchange" reRender="cpBlock" status="validationStatus"/>
  </apex:selectRadio>

  <apex:actionStatus id="validationStatus">
   <apex:facet name="start">Evaluating...</apex:facet>
   <apex:facet name="stop">Ready to Evaluate</apex:facet>
  </apex:actionStatus>

  <apex:PageBlock Title="Contact Page" id="cpBlock">
    <apex:pageBlockSection title="Details">
     <apex:PageBlockSectionItem rendered="{!renderName}">
       <apex:outputText value="First Name" />
       <apex:inputField value="{!contact.firstName}" id="cName"/>
     </apex:PageBlockSectionItem>
    </apex:pageBlockSection>
  </apex:PageBlock>


</apex:form>

/顶点:页面&GT;

<强>控制器

public class radioActionPageCtrl {

public Boolean renderName {
    get{
        return optSelected == 'Option1';
    }
}
public String optSelected {get;set;}
public List<SelectOption> radioValues {
    get {
        List<SelectOption> resList = new List<SelectOption>();
        resList.add(new SelectOption('Option1', 'Option1'));
        resList.add(new SelectOption('Option2', 'Option2'));
        return resList;
    }
}

public radioActionPageCtrl(ApexPages.StandardController controller) {
    optSelected  = 'Option1';
}

}