是否有可能使我的视觉力页面仅在特定条件下在视觉力组件中可见



我的visualforce页面中有一个元素列表,有时可能是空的。视觉力页面显示在主页上的视觉力组件中。我想知道如果列表为空,是否有可能隐藏组件。

<apex:repeat var="a" value="{!accounts}">
<apex:outputLabel for="link" value="{!a.Name} " />
</apex:repeat>

您可以使用rendered属性。类似的东西

<apex:repeat var "a" value="{!accounts}" rendered="{!NOT(AccountsEmpty)}">
<apex:outputLabel for="link" value="{!a.name}" />
</apex:repeat>

并在控制器中添加方法:

public boolean getAccountsEmpty(){
return this.accounts == null || this.account.size() == 0;
}

编辑:添加如何不呈现父组件/页面

这里有一些深入的文档,但简单地说,你需要添加一个属性到你的组件中重复,这样你就可以传入页面父页面/组件顶点控制器,例如,如果你的父页面有一个名为MyApexController的顶点控制器......

<apex:attribute name="controller" description="parent page controller" type="MyApexController" assignTo="{!pageController}"/>

然后,您可以从组件中使用公共getter和setter访问其成员 这是它的样子父页面控制器

public class MyApexController {
public boolean hasAccounts {get; set;}
public MyApexController(){
//Your controller constructor
}
}

子组件顶点控制器

public class MyComponentsController {
public List<Account> accounts {get; set;}
public MyApexController pageController {get; set;} //this will get set by apex:attibute
public MyComponentController(){
if(getAccountsEmpty()){
this.pageController.hasAccounts = false; //no accounts let parent page know
} else {
this.pageController.hasAccounts = true;
}
}
public boolean getAccountsEmpty(){
return this.accounts == null || this.account.size() == 0;
}

然后在父页面或组件上,只需向子组件添加类似的属性即可 父网页代码<apex:page rendered="{!hasAccounts}">

或父组件标记

<apex:component rendered="{!hasAccounts}">

最新更新