Salesforce中reRender和rendered控件的使用

导航:

1.reRender控件
2.rendered控件
3.代码演示

reRender控件

用途:局部刷新

这个属性的value值是组件的ID值,可以是一个或多个ID,多个ID用’,'隔开。

rendered控件

用途:可以控制一个控件在页面上是否能显示出来。

这个属性的value是一个Boolean值。如果是true,控件会在页面上显示,否则,不会在页面上显示。

代码演示

<apex:page standardController="ChannelPrice__c" extensions="TestDataList" action="{!init}">
	<apex:form>
		<apex:pageBlock title="渠道价格查询" mode="edit">
			<apex:pageBlockSection title="查询渠道价" columns="2">
				<table> 
					<tr>
						<apex:inputField value="{!cp.MATERIALCODE__c}" /> 
						<apex:inputField value="{!cp.CHANNELPRICENAME__c}" /> <br/>	 	 
						<apex:inputField value="{!cp.MATERIALNAME__c}" /> <br/>				 
				 		<apex:inputField value="{!cp.Brand__c}" /> <br/>				 
						<apex:CommandButton value="搜索" action="{!searchChannelPrices}" reRender="sec2"/>
					</tr>
				</table>
			</apex:pageBlockSection>
			<apex:pageBlockSection  title="搜索结果" columns="2" id="sec2">
				<apex:dataList value="{!channelPricesAdd}" var="channelPrice" style="padding-left: 0px;list-style: none;margin-left: 0px;">
					<table border="1" cellpadding="1" style="font-size: 1px;">
						<tr>
							<th style="text-align: center;">物料编码</th>
							<th style="text-align: center;">物料名称</th>
							<th style="text-align: center;">品牌</th>
							<th style="text-align: center;">类别</th>
							<th style="text-align: center;">价格</th>
							<th style="text-align: center;">数量(瓶)</th>
							<th style="text-align: center;">公司</th>
						</tr>
						<tr>
							<td>
								<apex:outputText value="{!channelPrice.MATERIALCODE__c}"/>
							</td>
							<td>
								<apex:outputText value="{!channelPrice.MATERIALNAME__c}"/>
							</td>
							<td>
								<apex:outputText rendered="{!IF(channelPrice.Brand__c=='百威', true, false)}" value="{!channelPrice.Brand__c}"/>
							</td>
							<td>
								<apex:outputText value="{!channelPrice.CHANNELPRICENAME__c}"/>
							</td>
							<td>
								<apex:outputText value="{!channelPrice.PRICE__c}"/>
							</td>
							<td>
								<apex:outputText value="{!channelPrice.StockBaseQuantity__c}"/> 
							</td>
							<td>
								<apex:outputText value="{!channelPrice.CompanyName__c}"/> 
							</td>
						</tr>
	        		</table>
	    		</apex:dataList>
	    	</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>	
</apex:page>

代码分析:
reRender控件引入到搜索按钮里面,并在搜索结果中将值传入到id
在这里插入图片描述
代码分析:
使用rendered控制Brand__c值的显示,当品牌等于 ‘百威’ 则会隐藏,否则就会显示
在这里插入图片描述
reRender添加多个id:

案例:

问题1:
通过以上代码,我如何使用一个按钮同时去控制两个组件呢?

直接上代码,这里我们先添加一个pageBlockSection标签,加入一个table

<apex:page standardController="ChannelPrice__c" extensions="TestDataList" action="{!init}">
	<apex:form>
		<apex:pageBlock title="渠道价格查询" mode="edit">
			<apex:pageBlockSection title="查询渠道价" columns="2">
				<table> 
					<tr>
						<apex:inputField value="{!cp.MATERIALCODE__c}" /> 
						<apex:inputField value="{!cp.CHANNELPRICENAME__c}" /> <br/>	 	 
						<apex:inputField value="{!cp.MATERIALNAME__c}" /> <br/>				 
				 		<apex:inputField value="{!cp.Brand__c}" /> <br/>				 
						<apex:CommandButton value="搜索" action="{!searchChannelPrices}" reRender="sec1,sec2"/>
					</tr>
				</table>
			</apex:pageBlockSection>
			<apex:pageBlockSection  title="搜索结果" columns="2" id="sec1">
				<apex:dataList value="{!channelPricesAdd}" var="channelPrice" style="padding-left: 0px;list-style: none;margin-left: 0px;">
					<table border="1" cellpadding="1" style="font-size: 1px;">
						<tr>
							<th style="text-align: center;">物料编码</th>
							<th style="text-align: center;">物料名称</th>
							<th style="text-align: center;">品牌</th>
							<th style="text-align: center;">类别</th>
							<th style="text-align: center;">价格</th>
							<th style="text-align: center;">数量(瓶)</th>
							<th style="text-align: center;">公司</th>
						</tr>
						<tr>
							<td>
								<apex:outputText value="{!channelPrice.MATERIALCODE__c}"/>
							</td>
							<td>
								<apex:outputText value="{!channelPrice.MATERIALNAME__c}"/>
							</td>
							<td>
								<apex:outputText rendered="{!IF(channelPrice.Brand__c=='百威', true, false)}" value="{!channelPrice.Brand__c}"/>
							</td>
							<td>
								<apex:outputText value="{!channelPrice.CHANNELPRICENAME__c}"/>
							</td>
							<td>
								<apex:outputText value="{!channelPrice.PRICE__c}"/>
							</td>
							<td>
								<apex:outputText value="{!channelPrice.StockBaseQuantity__c}"/> 
							</td>
							<td>
								<apex:outputText value="{!channelPrice.CompanyName__c}"/> 
							</td>
						</tr>
	        		</table>
	    		</apex:dataList>
	    	</apex:pageBlockSection>
	    	<apex:pageBlockSection  title="搜索结果2" columns="2" id="sec2">
				<apex:dataList value="{!channelPricesAdd}" var="channelPrice" style="padding-left: 0px;list-style: none;margin-left: 0px;">
	        		<table border="1" cellpadding="1" style="font-size: 1px;">
						<tr>
							<th style="text-align: center;">物料编码</th>
							<th style="text-align: center;">物料名称</th>
						</tr>
						<tr>
							<td>
								<apex:outputText value="{!channelPrice.MATERIALCODE__c}"/>
							</td>
							<td>
								<apex:outputText value="{!channelPrice.MATERIALNAME__c}"/>
							</td>
						</tr>
	        		</table>
	    		</apex:dataList>
	    	</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>	
</apex:page>

这里的第一个table的id修改为sec1,第二个table的id修改为sec2,加入到reRender中,用’,'隔开
在这里插入图片描述
这样便可以用时查询两个table:

看下查询结果
在这里插入图片描述

总结:这里对用Visualforce代码简单的做了一个reRender和rendered的分析,它们的功能使用大概就是如此。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值