problem with commandLink inside the Dataatble


J

jai- nigam

hi
the commandLink is working outside the dataatable but it is not
working inside the Datatable
the code is pasted below

controller,javva
package controller;



import java.util.ArrayList;
import java.util.List;

import javax.faces.component.UIParameter;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.http.HttpServletRequest;

import com.saintgobain.sgsi.dca.ui.bean.GroupBean;
import com.saintgobain.sgsi.dca.ui.bean.GroupListBean;
import com.saintgobain.sgsi.dca.ui.bean.PersonBean;

public class WelcomeControl {
private List personList;

private List groupList;

private int groupsize;
private String test;
// private List groupBeanList;

//private String radio;

//private List radioList;

public WelcomeControl(){
HttpServletRequest req =
(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
System.out.println("request params:" + req.getAttribute("name1"));
personList = new ArrayList();
PersonBean p1 = new PersonBean();
p1.setRole("");
p1.setAppGroup("");
PersonBean p2 = new PersonBean();
p2.setRole("");
p2.setAppGroup("");
PersonBean p3 = new PersonBean();
p3.setRole("");
p3.setAppGroup("");
PersonBean p4 = new PersonBean();
p4.setRole("");
p4.setAppGroup("");
personList.add(p1);
personList.add(p2);
personList.add(p3);
personList.add(p4);
groupList = new ArrayList();
this.groupsize = 1;
groupList.add(new GroupListBean(groupsize));
/*groupBeanList = new ArrayList();
groupBeanList.add(new GroupBean());
groupBeanList.add(new GroupBean());*/
}

public List getPersonList() {

return personList;
}

public void setPersonList(List personList) {
this.personList = personList;
}

public String doAddRow(ActionEvent e){
System.out.println("inside do add row=====================");
PersonBean p = new PersonBean();
personList.add(p);
return "success";
}
public void doDeleteRow(ActionEvent ae){
List id = ((HtmlCommandLink) ae.getComponent()).getChildren();
String toBeDeleted = (String)((UIParameter)(id.get(0))).getValue();
int i=0;
for (i=0;i<personList.size();i++){
PersonBean p = (PersonBean) personList.get(i);
personList.remove(i);

break;

}
/*ExternalContext context = FacesContext.getCurrentInstance()
.getExternalContext();
HttpServletRequest request = (HttpServletRequest)
context.getRequest();
String val = request.getParameter("toBeDeleted");
System.out.println("value to be deleted::::" + val);*/
// return "success";
}

public List getGroupList() {
// System.out.println("grouplist size::" + groupList.size());
return groupList;
}

public void setGroupList(List groupList) {
this.groupList = groupList;
}
public String doAddGroup(){
this.groupsize = this.groupsize + 1;
groupList.add(new GroupListBean(this.groupsize));
return "success";
}

public void doAddGroupColumn(ActionEvent e){
System.out.println(e.getComponent().getClass()
+"******************");
List id = ((HtmlCommandLink) e.getComponent()).getChildren();
Integer newColumn = (Integer)((UIParameter)(id.get(0))).getValue();
int i = newColumn.intValue();
((GroupListBean)groupList.get(i-1)).getGroup().add(new GroupBean());
}

public int getGroupsize() {
return groupsize;
}

public void setGroupsize(int groupsize) {
this.groupsize = groupsize;
}
public String doDelete(ActionEvent e){
System.out.println("*******************");
List id = ((HtmlCommandLink) e.getComponent()).getChildren();
Integer newColumn = (Integer)((UIParameter)(id.get(0))).getValue();
int x = newColumn.intValue();
System.out.println("the value of x"+x);
List list = new ArrayList();
// list = ((GroupListBean)groupList.get(x-1)).getGroup();
for (int
i=0;i<((GroupListBean)groupList.get(x-1)).getGroup().size();i++){
list.add(((GroupListBean)groupList.get(x-1)).getGroup().get(i));
}
int count = 0;
for (int i=0;i<list.size();i++){
GroupBean gBean = (GroupBean)list.get(i);
System.out.println(i + " " + gBean.isDelete() +
((GroupListBean)groupList.get(x-1)).getGroup().size());
if (gBean.isDelete() == true){
count++;
System.out.println("list size::::" +
((GroupListBean)groupList.get(x-1)).getGroup().size());
if (((GroupListBean)groupList.get(x-1)).getGroup().size() != 1)
((GroupListBean)groupList.get(x-1)).getGroup().remove(gBean);
}
}
return "";
}
public void doDeleteGroup(ActionEvent e) {

List id = ((HtmlCommandLink) e.getComponent()).getChildren();
System.out.println(e.getComponent().getClass()
+"******************");
Integer newColumn = (Integer)((UIParameter)(id.get(0))).getValue();
int x = newColumn.intValue();
for(int i=0;i<groupList.size();i++){
GroupListBean bean = (GroupListBean)groupList.get(i);
if (bean.getIndex() == (x)){
x = i;

break;

}

}
Object obj = groupList.get(x);
groupList.remove(obj);
for (int i=x;i<groupList.size();i++){

}
}

public String doSave() {
System.out.println("doSave() called...");
System.out.println("*****************" + getGroupList().size());
if (getGroupList() != null && getGroupList().size() >0) {
int size = getGroupList().size();
GroupListBean listBean = null;
for (int i = 0; i < size; i++) {
listBean = (GroupListBean) getGroupList().get(i);
System.out.println("Getting list bean contents:::" +
listBean.getGroupName());
//Service service = new Service();
//Call call = (Call) service.createCall();




//ArrayList list= new ArrayList();
//Iterator it=(Iterator) list.iterator();
//while(it.hasNext())
//{
//System.out.println("The list is iterated " +
it.next());
//}


}
}

return "success";
}

public String getTest() {
return test;
}

public void setTest(String test) {
this.test = test;
}

}
}

jsf for this controller

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<LINK rel="stylesheet" type="text/css" href="../themes/style.css"
title="Style">
<script type="text/javascript" src="../js/createform.js"></script>
<title>Data Centric Application - Create Form</title>
</HEAD>
<BODY>
<f:view>
<h:form id="createForm">
<h:panelGrid width="895" styleClass="TrameTableResult" id="pnl2"
border="3">
<h:eek:utputText id="results" value="Create Form" />
<h:eek:utputText id="lblNoOfSearchRecords" />
</h:panelGrid>
<h:panelGrid width="695" columns="2" id="row2PanelGrids" border="1">
<h:eek:utputText id="FormText" value="Form Name /Nom de la forme "
styleClass="sgTextNormalMediumBold" />

<h:inputText id="formText1" size="15" />
<h:eek:utputText id="FormDesc" value="Form Description "
styleClass="sgTextNormalMediumBold" />
<h:inputText id="FormDesc1" size="15" />
<h:eek:utputText id="NoofpagesText"
value="Number of rows for pagination "
styleClass="sgTextNormalMediumBold" />
<h:inputText id="pages1" size="15" />
<h:eek:utputText id="NorowsText" value="Number of Entries "
styleClass="sgTextNormalMediumBold" />
<h:eek:utputText id="Scopcheck" value="Scope:"
styleClass="sgTextNormalMediumBold" />

<%--<h:panelGroup id="bttnGrp"
style="padding-top: 10px;padding-right:470px;">

<h:commandButton id="CreateNewBtn" value="CreateNewGroup"
styleClass="buttonAction"
actionListener="#{welcomeController.doAddGroup}"
/>

</h:panelGroup>--%>
<h:commandButton id="createNewBtn" value="CreateNewGroup"
immediate="true" action="#{welcomeController.doAddGroup}">
</h:commandButton>
</h:panelGrid>

<h:dataTable value="#{welcomeController.groupList}" var="var1"
id="groupTable">

<h:column id="colOne">
<h:panelGrid width="895" styleClass="TrameTableResult"
id="groupGridOne">
<h:panelGroup styleClass="backgroundTableResult"
style="height:4px;" id="groupGroupOne">
<h:eek:utputText id="results1" value="Group#{var1.index}" />
<h:eek:utputText styleClass="padding-left:30%;" id="addresses" />
<h:commandLink id="deletegroup" value="Delete Group"
actionListener="#{welcomeController.doDeleteGroup}">
<f:param value="#{var1.index}" name="delGr" id="delGr" />
</h:commandLink>
</h:panelGroup>

</h:panelGrid>
<h:panelGrid width="895" columns="5" id="row2Panel">
<h:eek:utputText id="GroupnameTextt" value="Enter Group Name "
styleClass="sgTextNormalMediumBold" />
<h:inputText id="groupnameText1" size="15"
value="#{var1.groupName}" />
<h:commandLink id="InseNewAttBtn" value="New Attribute"
actionListener="#{welcomeController.doAddGroupColumn}">

<f:param value="#{var1.index}" name="newColumn" id="newColumn" />
</h:commandLink>






<h:eek:utputText id="grouporderTextt1" value="Group Order "
styleClass="sgTextNormalMediumBold" />
<h:inputText id="grouporderText2" size="15"
value="#{var1.groupOrder}" />
</h:panelGrid>
<h:dataTable id="groupColumnId" value="#{var1.group}"
var="grouplist"
width="895">
<h:column id="col1GC">
<f:facet name="header">
<h:eek:utputText id="LabelText" value="Label"
styleClass="sgTextNormalMediumBold" />
</f:facet>
<h:inputText id="labelText1" size="15"
value="#{grouplist.label}" />
</h:column>
<h:column id="col2GC">
<f:facet name="header">
<h:eek:utputText id="ControlText" value="Control Type"
styleClass="sgTextNormalMediumBold" />
</f:facet>
<h:selectOneListbox>
</h:selectOneListbox>
</h:column>
<h:column id="col3GC">
<f:facet name="header">
<h:eek:utputText id="MandatoryText" value="Mandatory"
styleClass="sgTextNormalMediumBold" />
</f:facet>
<h:selectBooleanCheckbox id="Mandcheck1"
value="#{grouplist.mandatory}" />
</h:column>
<h:column id="col4GC">
<f:facet name="header">
<h:eek:utputText id="PreviewText" value="Preview Field"
styleClass="sgTextNormalMediumBold" />
</f:facet>
<h:selectBooleanCheckbox id="Previewcheck2"
value="#{grouplist.prfield}" />
</h:column>
<h:column id="col5GC">
<f:facet name="header">
<h:eek:utputText id="DefaultText" value="Default Values"
styleClass="sgTextNormalMediumBold" />
</f:facet>
<h:inputText id="defaultText1" size="15"
value="#{grouplist.defaultValue}" />
</h:column>
<h:column id="col6GC">
<f:facet name="header">
<h:eek:utputText id="OrderText" value="Field Order" />
</f:facet>
<h:inputText id="orderText1" value="#{grouplist.order}"
size="10" />
</h:column>
<h:column id="col7GC">
<f:facet name="header">
<h:commandLink id="Deletebtn" value="Delete"
styleClass="buttonAction" immediate="true"
actionListener="#{welcomeController.doDelete}">
<f:param value="#{var1.index}" name="newColumn"
id="deleteColumn" />
</h:commandLink>
</f:facet>
<h:selectBooleanCheckbox id="deletecheck3"
value="#{grouplist.delete}"/>
</h:column>
</h:dataTable>
</h:column>
</h:dataTable>
<h:panelGrid width="895" styleClass="TrameTableResult">
<h:panelGroup styleClass="backgroundTableResult" style="height:
4px;">
<h:eek:utputText id="Accesstitle" value="Applicative Groups" />
<h:eek:utputText styleClass="padding-left:30%;"
id="lblNoOfSearchRecords1" />
</h:panelGroup>
<h:panelGrid width="695" columns="4" id="row2PanelGrid">
<h:dataTable id="dataTableId1"
value="#{welcomeController.personList}" var="list">
<h:column id="column1">
<f:facet name="header">
<h:eek:utputText id="column1header" value="Role"></h:eek:utputText>
</f:facet>
<h:inputText id="roleId" value="#{list.role}"></h:inputText>
</h:column>
<h:column id="column2">
<f:facet name="header">
<h:eek:utputText id="column2header" value="Applicative Group"></
h:eek:utputText>
</f:facet>
<h:inputText id="appGroupId" value="#{list.appGroup}"></
h:inputText>
</h:column>
<h:column id="column3">
<h:commandLink id="addBtnid" value="Add" immediate="true"
actionListener="#{welcomeController.doAddRow}">
</h:commandLink>
</h:column>
<h:column id="column4">
<h:commandLink id="deleteBtnId" value="Delete" immediate="true"
actionListener="#{welcomeController.doDeleteRow}">
<f:param value="#{list.role}" name="toBeDeleted"
id="toBeDeleted" />
</h:commandLink>
</h:column>
</h:dataTable>
</h:panelGrid>
</h:panelGrid>
<h:panelGrid id="bttnGrp1" columns="2" width="30%"
style="padding-top: 10px;padding-left:470px;">
<h:commandLink id="printBtn1" value="Save"
styleClass="buttonAction"
onmousedown="return Form1_Validator();" />
<h:commandLink id="exportBtn1" value="Cancel"
styleClass="buttonAction" onmousedown="return disp_confirm1();" />
</h:panelGrid>
</h:form>
</f:view>
</BODY>
</HTML>

comment : all the commandLinks are working fine except this
commandLink :
<h:commandLink id="Deletebtn" value="Delete"
styleClass="buttonAction" immediate="true"
actionListener="#{welcomeController.doDelete}">
<f:param value="#{var1.index}" name="newColumn"
id="deleteColumn" />
</h:commandLin
please help me. i am trying too hard..

Thanks
Jai
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top