问题描述
我正在创建一个虚拟的Visualforce页面,其代码为
i am creating a dummy visualforce page whose code is
<apex:page controller="sampleCon">
<apex:form>
<apex:pageMessages id="message" />
<apex:pageBlock>
<apex:pageBlockTable value="{!wrap1}" var="item" id="hello">
<apex:column headerValue="String" value="{! item.x}"></apex:column>
<apex:column headerValue="Action"><apex:commandButton value="{!if(item.i == size-1,'Add','Delete')}" onclick="AddOrDelete({! item.i});" rerender="message"></apex:commandButton></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:actionRegion >
<apex:actionFunction name="AddOrDelete" action="{!addElement}" reRender="message,hello">
<apex:param value="" name="fieldName" />
</apex:actionFunction>
</apex:actionRegion>
</apex:form>
</apex:page>
并且控制器代码为
public class sampleCon {
public List<Wrapper> wrap1{get;set;}
public Integer size{get;set;}
public sampleCon(){
wrap1=new List<Wrapper>();
wrap1.add(new wrapper(0));
size=wrap1.size();
}
public PageReference addElement(){
size=wrap1.size();
System.debug('Hello ji'+Apexpages.currentPage().getParameters().get('fieldName')+'size is'+size);
Integer i=Integer.valueOf(ApexPages.currentPage().getParameters().get('fieldName'));
if(i == size-1)
{
wrap1.add(new wrapper(size));
size++;
}
return null;
}
public class wrapper{
public integer i{get;set;}
public String x{get;set;}
public wrapper(Integer p){
i=p;
}}
}
我正在尝试的是最后一行按钮标签应为添加",其他按钮标签应为删除",当我按添加"按钮时,将添加新行,并且为此,标签应相应更改,我正在添加行,但不是按预期工作
what i am trying is the last row button label should be Add and other button label should be Delete when i press add button a new row is added and the label should be changed acordingly for this i am adding row but it is not working as expected
初始屏幕截图为当我按添加按钮屏幕看起来像这样.当我再次按下添加按钮时,屏幕看起来像第一个屏幕截图.我期望当我在上面的屏幕快照中单击添加按钮时会再添加一行.请问为什么当我单击添加按钮时仅显示一行第二个屏幕快照以及如何纠正它,当我再次单击屏幕上方的添加按钮时,将添加另一行而不是显示初始屏幕.
initial page screenshot iswhen i press add button screen look like this.when i again press the Add button screen is looking like first screenshot.i was expecting that one more row will be added when i click add button in above screenshot.can any one please tell why only one row is showing when i click add button in second screen shot and how to correct it that when i again click on add button on above screen one more row will be added instead of showing initial screen.
推荐答案
我建议您在下面的帖子中列出一个列表:
I would suggest you take a list at below post:
希望这会有所帮助.
这篇关于在PageBlocktable中的visualforce页面中动态添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!