1

我在这里停留在我呈现的论点上——我相当肯定我是从记录本身而不是从 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 的更改,仍然存在切换渲染的布尔值的问题 - 我将如何在控制器中切换它?我想我需要评估 inputField 值是否 = 否,然后将渲染设置为 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();
}
4

1 回答 1

5

将元素包裹在 an 中<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"/>

希望有帮助!

于 2012-01-23T21:50:49.853 回答