2013-02-24 83 views
0

渲染属性我写了visualforce页面的源代码重新呈现在visualforce

和MyController1类是

public class MyController1{ 
public Boolean rend{get;set;} 
public PageReference commandLinkAction(){ 
rend=true; 
return null; 
} 

} 

当我点击高级搜索链接没有任何反应,但我期待outputPanel用id“thePanel”应该渲染。为什么不渲染请别人解释?

回答

2

在您点击链接面板不在页面上时,SF没有呈现它。

+0

+1但它是一个没有帮助的答案:)你能扩展一下这个答案吗?就像“它必须被渲染,它可以被初始隐藏(样式设置为'visibility:none'或'display:hidden'),但是它需要在页面中占位符。另外,AJAX调用将不知道在哪里注入新鲜内容“;) – eyescream 2013-02-25 19:45:02

0

请尝试下面的代码。

<apex:page controller="MyController1"> 
<apex:form> 
<apex:pageBlock > 
<apex:pageBlockSection id="search"> 
<apex:commandLink action="{!commandLinkAction}" value="Advance Search" reRender="thePanelWrapper" id="theCommandLink"/> 
<apex:outputPanel id="thePanelWrapper"> 
<apex:outputPanel id="thePanel" rendered="{! rend}" layout="block">My div</apex:outputPanel> 
</apex:outputPanel> 
</apex:pageBlockSection> 
</apex:pageBlock> 
</apex:form> 
</apex:page> 

public class MyController1{ 
    public Boolean rend{get;set;} 
    //setting the boolean to false in the constructor 
    public MyController1(){ 
      rend = false; 
    } 
    public void commandLinkAction(){ 
     rend=true; 
    // return null; 
    } 

} 

希望这有助于!

0

正如@Shimshon所说,当从Visualforce生成HTML代码时,标记为rendered="false"的Visualforce组件不会显示在生成的HTML文档中。

在这种情况下:

<apex:outputPanel id="thePanel" rendered="{! rend}" layout="block"> 

如果你要重新呈现此面板,则必须确保该组件将被显示在HTML代码,以便重新呈现动作可以找到它。由于{! rend}在控制器的构造函数中最初设置为false,因此“页面”永远不会呈现在页面中,因此您尝试重新渲染不存在的组件。

@theGreatDanton的解决方案将工作,因为<apex:outputPanel id="thePanelWrapper">是始终呈现容器板:

<apex:commandLink action="{!commandLinkAction}" value="Advance Search" reRender="thePanelWrapper" id="theCommandLink"/> 

,如果这个面板指向通过重新呈现属性,然后在‘thePanelWrapper’及其子节点(“thePanel “) 将会被更新。