I'm struggling to create a binding to a UIInput element in a DataTable row.
(Context: I'm trying to do validation across multiple fields in the same
row.) 

I have a backing bean for the main page (PlayBB; managed-bean-scope:
"session") which contains a List of backing beans for each row (NameBB;
managed-bean-scope: "none"). I've observed (through logging) that the
binding occurs exactly once per page and not once per row as I had expected.

Can one not bind to elements in a row? Do I need to bind the entire table
instead and  traverse the elements to do validation?

Thanks to anyone who can help.

-David-

Here's the relevant code:

-----------JSP-----------
<%@ taglib uri="http://java.sun.com/jsf/html"; prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core"; prefix="f" %>

<html>
<head><title>JSF Play</title></head>
<body>

<f:view>
<h:form id="form">

<h:commandButton value="Add Names" type="submit" action="#{play.addNames}"/>

<h:dataTable id="names" value="#{play.nameBBList}" var="name"
rendered="#{play.numberOfNames > 0}"> 
 <h:column>    

    <h:inputText id="first" value="#{name.first}" maxlength="10" size="10"
binding="#{name.firstInput}" />
    <h:inputText id="last" value="#{name.last}" maxlength="10" size="10"/>

 </h:column>
</h:dataTable>

</h:form>
</f:view>

</body></html>
-----------JSP-----------

---------PlayBB.java----------
package jsfplay;
import java.util.*;
public class PlayBB {
    
  private List<NameBB> nameBBList=new ArrayList<NameBB>();

  public PlayBB(){ }
    
  public int getNumberOfNames() { return nameBBList.size();  }
  
  public List<NameBB> getNameBBList() { return nameBBList;}

  public String addNames() {
    // fill in some names.
    NameBB newName = new NameBB("Joe","Smith");
    nameBBList.add(newName);
    newName = new NameBB("Ralph","Johnson");
    nameBBList.add(newName);
    return null;
  }
}
---------PlayBB.java----------

---------NameBB.java----------
package jsfplay;
import javax.faces.component.*;
public class NameBB {
    
    //properties
  private String first="";
  private String last="";
  private UIInput firstInput;
  private UIInput lastInput;
  
  public NameBB(){ }
  public NameBB(String first, String last)
  {
    this.first=first;
    this.last=last;
  }
    
  public String getFirst() {return first;}
  public String getLast() {return last;}

  public void setFirst(String first) {this.first=first;}
  public void setLast(String last) {this.last=last;}

  public void setFirstInput(UIInput firstInput) 
  {
    System.out.println("FirstInput was set.");
    this.firstInput=firstInput;
  }
  public UIInput getFirstInput() {return firstInput; }
}
---------NameBB.java----------

-- 
View this message in context: 
http://www.nabble.com/Binding-to-elements-in-DataTable-tf2041529.html#a5619707
Sent from the MyFaces - Users forum at Nabble.com.

Reply via email to