Salesforce (Visualforce):重新渲染 - 从页面而不是记录中提取值?

发布于 2024-12-28 21:06:54 字数 3324 浏览 2 评论 0 原文

我在这里坚持我的渲染论点 - 我相当肯定我是从记录本身而不是从 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 值是否 = 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();
}

I'm stuck on my rendered argument here - I'm fairly positive i'm pulling values from the record itself and not from the visualforce page. When I change the value (are_you_kp__c) from the record to a "No" - the pageblocksection shoud render, but for some reason it doesn't. Does anybody know why?

I think I need some controller work here - but not sure where to go from here...

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

Updated - wrapped the to be rendered element in outputPanel with correct id: Still have the problem of toggling my rendered boolean as a result of a change on an inputField - how would I toggle this in the controller? I think i need to evaluate if the inputField value = No, and set the rendered to true by that - i'm not sure how though...

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

Alright one more attempt - this time it works, but I don't quite get why...only that it does. This is in addition to adding action="{!updateAnswer}" to the actionSupport above (or below, whichever way you see it)

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

Probably relevant controller code

public ProposalExtension(ApexPages.StandardController pCon) {
    this.p = (Proposal__c)pCon.getRecord();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由范儿 2025-01-04 21:06:54

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

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

**编辑**

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

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

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

希望有帮助!

Wrap the element in an <apex:outputPanel> and re-render that, not the element you want to appear. The problem is that the element isn't in the page when it's not rendered, so it's not a working target for re-render.

It's something that often catches people out, myself included — I wrote a blog post about it here: http://www.laceysnr.com/2011/10/using-rerender-to-render-one-solution.html

** EDIT **

Didn't spot before that you didn't have an action specified in your <apex:actionSupport> tag. You can use that to call the action on the controller. Since the select list is writing to the value you want, you don't actually need to do anything in the code (unless you want to) you could just do this:

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

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

Hope that helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文