在PageBlocktable中的visualforce页面中动态添加行 [英] Adding rows in visualforce page in PageBlocktable dynamically

查看:23
本文介绍了在PageBlocktable中的visualforce页面中动态添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个虚拟的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>

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

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/m-p/358921

Hope this helps.

这篇关于在PageBlocktable中的visualforce页面中动态添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆