1

I need to provide the user with a button (CommandButton) on the form which by clicking it can add TextInputs to the form. But it is not needed to be DHTML or AJAX

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ehsun7b
  • 4,796
  • 14
  • 59
  • 98
  • 1
    Related: http://stackoverflow.com/questions/2278353/how-to-dynamically-add-a-row-in-a-table-in-jsf – BalusC Mar 09 '11 at 12:15

1 Answers1

1

I was writing this code..hoping to solve your problem,

JSF page:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html">
<h:head>
    <title>Dynamic Input</title>
</h:head>
<h:body>
    <h:form>
 <h:dataTable id="textlist"  var="tbox" value="#{Bean.inputList}">
  <h:column>
      <h:inputText value="#{tbox}"/>
  </h:column>
</h:dataTable>
        <h:commandButton action="#{Bean.addInput}" value="Add Textbox"/>
    </h:form>
</h:body>
</html>

Bean:

import java.util.ArrayList;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;


@ManagedBean(name="Bean")
@ViewScoped
public class Bean implements java.io.Serializable {
private ArrayList inputList;
/** Creates a new instance of Bean */
public Bean() {
   inputList=new ArrayList();
    inputList.add(inputList.size());
}

public void addInput(){
     inputList.add(inputList.size());
}

public ArrayList getInputList() {
    return inputList;
}

public void setInputList(ArrayList inputList) {
    this.inputList = inputList;
}

}

This works...as a start. You can see if you can modify the code to suite your purposes. :)

I dont know if any other approach exist to add dynamic controls in JSF 2.0

Selvin
  • 12,333
  • 17
  • 59
  • 80