2011-03-09 50 views
1

我需要为用户提供表单上的按钮命令按钮),它通过单击它可以添加TextInputs到窗体。但它并不需要是DHTMLAJAXJSF添加输入到表格

+1

相关:http://stackoverflow.com/questions/2278353/how-to-dynamically-add-a-row- IN-A-表中的JSF – BalusC

回答

1

我写这篇code..hoping解决您的问题,

JSF页面:

<?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> 

豆:

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; 
} 

}

这工作...作为一个开始。你可以看看你是否可以修改代码来适应你的目的。 :)

我不知道是否有其他方法存在于JSF添加动态控件2.0