>Aha! Now I see what your issue is. Before, I thought your hidden
>component was enclosed in a <h:column>, and I couldn't understand why
>you needed to change the row index. If you're only working within a
>row, then by doing this, you'd avoid having to mess around with
>setting the row index.
>Obviously, if you're validating across rows, then you'll need to do it
>as you stated above.
I'm glad you wrote - you just saved me bunches of coding time. Indeed, if I
have the hidden component within the <h:column>, then I don't need to set
the row index.
My original struggle was where to bind the row UIInputs and the validation
method - the solution is on the overall page backing bean, not on the row
backing bean.
-David-
Here are the relevant code changes:
play.jsp:
<h:dataTable id="names" value="#{play.nameBBList}" var="name">
<h:column>
<h:inputText id="first" value="#{name.first}" maxlength="10" size="10"
binding="#{play.firstInput}" />
<h:inputText id="last" value="#{name.last}" maxlength="10" size="10"
binding="#{play.lastInput}" />
<h:inputHidden id="datacheck" validator="#{play.validateNames}"
value="dummy"/>
</h:column>
</h:dataTable>
PlayBB.java: (no need to access UIData)
public class PlayBB {
private UIInput firstInput;
private UIInput lastInput;
private List<NameBB> nameBBList=new ArrayList<NameBB>();
public PlayBB(){ }
public int getNumberOfNames() { return nameBBList.size(); }
public List<NameBB> getNameBBList() { return nameBBList;}
public String addNames() { ... }
public void setFirstInput(UIInput firstInput) {
this.firstInput=firstInput; }
public UIInput getFirstInput() {return firstInput; }
public void setLastInput(UIInput lastInput) { this.lastInput=lastInput; }
public UIInput getLastInput() {return lastInput; }
public void validateNames(FacesContext context, UIComponent toValidate,
Object value) throws ValidatorException {
// Now do validation comparing firstInput.getValue() and
// lastInput.getValue()
}
}
--
View this message in context:
http://www.nabble.com/Binding-to-elements-in-DataTable-tf2041529.html#a5622138
Sent from the MyFaces - Users forum at Nabble.com.