2017-06-09 37 views
0
<p:outputPanel id="panel"> 
<ui:repeat value="#{dataController.display()}" 
var="item" rendered="#{Bean.showtable}"> 
    <b:row> 
    <b:column col-md="5"> 
    <h:outputText value="#{item.name}" style="font-family: verdana;font-size:16px;margin-bottom:15px;"></h:outputText> 
    </b:column>  

    <b:column col-md="7"> 
    <h:inputText style="width:200px;height:30px;margin-bottom:15px;" 
          autocomplete="off"></h:inputText> 
    </b:column>       
    </b:row> 
    </ui:repeat> 

访问值:重复JSF

在上面的代码中,我使用UI:重复用于输出在一个列表中显示的项目名称文本以及输入文本用于输入项目的

输入文本取决于列表中的值,即动态生成。

我需要从输入文本访问值并将它们添加到List。

任何人都可以请建议我一种方法来访问值从输入文本到bean /列表尽管使用ui:重复一次显示输入文本?

我试图创建一个空列表,并再次使用ui:只对输入文本重复..试图从输入文本访问值。但ui:重复不再工作..因为它已经用于显示一次。

我是新来的JSF.Any帮助将不胜感激。Thankyou。

回答

1

请勿使用空列表。用空值或空值初始化它。
假设我们有inputs作为您的列表,您的应该看起来像这样。

@Named 
@ViewScoped 
public class DataController implements Serializable { 

    private List<String> inputs; 

    // getters and setters 

    @PostConstruct 
    public void init() { 
     inputs = new ArrayList<String>(); 
    } 

    public List<Bean> getDisplay() { 
     List<Bean> display = new ArrayList<Bean>(); 

     // add values to display 

     for (int i = inputs.size(); i < display.size(); i++) { 
      inputs.add(""); 
     } 

     return display; 
    } 

    // for testing inputs 
    public void testInputs() { 
     for (String input : inputs) { 
      System.out.println(">>>>>" + input); 
     } 
    } 

} 

XHTML

<ui:repeat value="#{dataController.display()}" varStatus="idx" ...> 
    ... 
    <h:inputText value="#{dataController.inputs[idx.index]}" style="width:200px;height:30px;margin-bottom:15px;" autocomplete="off"></h:inputText> 
    ... 
</ui:repeat> 

<p:commandButton value="Test Inputs" action="#{dataController.testInputs}" update="@form" /> 

希望这有助于。

+0

非常感谢您的解决方案。 – Spandana

+0

但是** dataController.display()**是一种返回**列表 **的方法,我不能初始化init()中的显示方法,因为它需要在另一个方法调用之后调用。 – Spandana

+0

你可以告诉我,如果我可以使用嵌套的** UI:重复**或任何其他方法建议? – Spandana