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
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
精彩评论