我在这里坚持我的渲染论点 - 我相当肯定我是从记录本身而不是从 Visualforce 页面中提取值。当我将值 (are_you_kp__c) 从记录更改为“否”时 - pageblocksection 应该呈现,但由于某种原因它不会呈现。有人知道为什么吗?

我想我需要在这里进行一些控制器工作 - 但不知道从这里去哪里......

<apex:pageBlock title="New Bid" mode="maindetail" tabStyle="Proposal__c">
    <apex:messages/>
    <apex:actionRegion>
    <apex:pageBlockSection columns="2" title="Bid Information" collapsible="false" showHeader="true">
        <apex:inputField value="{!rfp.Bid_Amount__c}"/>
        <apex:outputField value="{!rfp.Bid_Date__c}"/>
        <apex:inputField value="{!rfp.Bid_Deliver_By__c}"/>
        <apex:inputField value="{!rfp.Bid_Comments__c}"/>
        <apex:pageBlockSectionItem>
               <apex:outputLabel value="Are you the Key Appraiser?"/>
               <apex:outputPanel>             
                   <apex:inputField value="{!rfp.are_you_kp__c}" required="true">
                       <apex:actionSupport status="StatusChange" event="onchange" rerender="PageErrors, appraiserInfo"/>
                       <apex:actionStatus startText="Updating page ..." id="StatusChange"/>
                   </apex:inputField>  
               </apex:outputPanel>
        </apex:pageBlockSectionItem> 
    </apex:pageBlockSection>
    </apex:actionRegion>
    <apex:pageBlockSection title="Testing" columns="2" rendered="{!rfp.are_you_kp__c == 'No'}" id="appraiserInfo">
        <apex:pageBlockSectionItem>
            <apex:outputLabel value="Single Point of Contact" for="spoc"/>
                <apex:selectList id="spoc" value="{!rfp.SPOCL__c}" size="1" title="Single Point of Contact Select">
                    <apex:selectOptions value="{!SPOCS}"></apex:selectOptions>
                </apex:selectList>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
</apex:pageBlock>

更新 - 使用正确的 id 将要渲染的元素包装在 outputPanel 中:仍然存在由于输入字段的更改而切换渲染的布尔值的问题 - 我将如何在控制器中切换它?我认为我需要评估 inputField 值是否 = No,并将渲染设置为 true - 我不知道如何...

<apex:outputPanel id="appraiserInfo">
<apex:pageBlockSection title="Testing" columns="2" rendered="{!rfp.are_you_kp__c == 'No'}">
    <apex:pageBlockSectionItem>
        <apex:outputLabel value="Single Point of Contact" for="spoc"/>
            <apex:selectList id="spoc" value="{!rfp.SPOCL__c}" size="1" title="Single Point of Contact Select">
            <apex:selectOptions value="{!SPOCS}"></apex:selectOptions>
            </apex:selectList>
    </apex:pageBlockSectionItem>
</apex:pageBlockSection></apex:outputPanel>

好吧,再尝试一次 - 这次它起作用了,但我不太明白为什么......只是它起作用了。这是除了将 action="{!updateAnswer}" 添加到上面(或下面,无论您以哪种方式看到)的 actionSupport 之外的内容

    public pageReference updateAnswer(){
       if(this.p.are_you_kp__c == 'No')
       rfp.are_you_kp__c = 'No';
       try{
        update rfp;
          }
        catch (DmlException ex){
            ApexPages.addMessages(ex);
            return null;
       }
       return null;
    }

可能相关的控制器代码

public ProposalExtension(ApexPages.StandardController pCon) {
    this.p = (Proposal__c)pCon.getRecord();
}
有帮助吗?

解决方案

将元素包裹在 <apex:outputPanel> 并重新渲染它,而不是您想要显示的元素。问题是该元素在未渲染时并不在页面中,因此它不是重新渲染的工作目标。

这常常让人们感到困惑,包括我自己——我在这里写了一篇关于它的博文: http://www.laceysnr.com/2011/10/using-rerender-to-render-one-solution.html

** 编辑 **

之前没有发现您的操作中没有指定操作 <apex:actionSupport> 标签。您可以使用它来调用控制器上的操作。由于选择列表正在写入您想要的值,因此您实际上不需要在代码中执行任何操作(除非您愿意),您可以这样做:

// controller
public Pagereference UpdateAnswer()
{
  // do some stuff if you want
  return null
}

// page
<apex:actionSupport action="{!UpdateAnswer}" status="StatusChange" event="onchange" rerender="PageErrors, appraiserInfo"/>

希望有帮助!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top