[英]Adding rows in visualforce page in PageBlocktable dynamically
i am creating a dummy visualforce page whose code is 我正在创建一个虚拟的visualforce页面,其代码为
<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>
and the controller code is 控制器代码是
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 我正在尝试的是最后一行按钮标签应为Add,其他按钮标签应为Delete,当我按添加按钮时,将添加新行,并且为此应相应地更改标签,我正在添加行,但未如预期
initial page screenshot is 初始页面截图为 when 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: 我建议您在下面的帖子中列出一个清单:
http://boards.developerforce.com/t5/Visualforce-Development/Add-Row-functionality-in-VisualForce/mp/358921 http://boards.developerforce.com/t5/Visualforce-Development/Add-Row-functionality-in-VisualForce/mp/358921
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.