This is what I have done uptil now and it seems to be working fine.
MyPage.jsp
<td colspan="4"><h:panelGrid binding="#{hostSelection.grid}"/></td>
<h:commandButton id="Add" styleClass="buttonStyle" value="#{label.addButton}" title="#{label.addButton}" actionListener="#{myPage.addNewHost}" />
MyPage.java
private List<HostObj> list = new ArrayList<HostObj>();
private HtmlPanelGrid grid;
HtmlInputText txtIP,txtDir,txtJavaHome,txtOracleHome;
HtmlOutputText txtSec;
HtmlCommandLink removeHost;
public void addNewHost(ActionEvent event){
context = FacesContext.getCurrentInstance();
id = (++integerId).toString();
HostObj hostObj = new HostObj();
txtIP = new HtmlInputText();
txtIP.setStyleClass("INPUT");
txtIP.setId(txtIP.getClientId(context)+id);
txtIP.setValue(hostObj.getIpAddress());
txtDir = new HtmlInputText();
txtDir.setStyleClass("INPUT");
txtDir.setId(txtDir.getClientId(context)+id);
txtDir.setValue(hostObj.getDirPath());
txtSec = new HtmlOutputText();
txtSec.setStyleClass("bodyText");
txtSec.setId(txtSec.getClientId(context)+id);
txtSec.setValue("Secondary");
txtJavaHome = new HtmlInputText();
txtJavaHome.setStyleClass("INPUT");
txtJavaHome.setId(txtJavaHome.getClientId(context)+id);
txtJavaHome.setValue(hostObj.getJavaHome());
txtOracleHome = new HtmlInputText();
txtOracleHome.setStyleClass("INPUT");
txtOracleHome.setId(txtOracleHome.getClientId(context)+id);
txtOracleHome.setValue(hostObj.getOracleHome());
removeHost = new HtmlCommandLink();
removeHost.setValue("remove");
removeHost.setId(removeHost.getClientId(context)+id);
grid.setColumns(6);
grid.getChildren().add(txtIP);
grid.getChildren().add(txtSec);
grid.getChildren().add(txtDir);
grid.getChildren().add(txtJavaHome);
grid.getChildren().add(txtOracleHome);
grid.getChildren().add(removeHost);
context.getViewRoot().setTransient(true);
}
public HtmlPanelGrid getGrid(){
return grid;
}
public void setGrid(HtmlPanelGrid grid){
this.grid = grid;
}
HostObj.java
public class HostObj{
private
String ipAddress;
private String dirPath;
private String javaHome;
private String oracleHome;
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public String getDirPath() {
return dirPath;
}
public void setDirPath(String dirPath) {
this.dirPath = dirPath;
}
public String getJavaHome() {
return javaHome;
}
public void setJavaHome(String javaHome) {
this.javaHome = javaHome;
}
public String getOracleHome() {
return oracleHome;
}
public void setOracleHome(String oracleHome) {
this.oracleHome = oracleHome;
}
}
when we call a backing bean method, it adds the new row of components everytime.
Now my requirement is that, I want to add a new commandlink on each row of components and register an actionlistener for it. When we click the command
link, the corresponding row of the components should be removed.
Thanks,