There's nothing wrong with the datatable. There's only one UIInput
component in the JSF component tree whose state get changed everytime whenever the parent UIData
component iterates over every item of the model. The state is thus only available during the UIData
iteration and not before or after. You're trying to access the value of a single component in the bean's action method while the parent UIData
component isn't iterating over it, so the values will always return null
.
You need to visit the component tree by UIComponent#visitTree()
on the UIData
and collect the information of interest in the VisitCallback
implementation.
table.visitTree(VisitContext.createVisitContext(FacesContext.getCurrentInstance()), new VisitCallback() {
@Override
public VisitResult visit(VisitContext context, UIComponent target) {
if (target instanceof UIInput) {
UIInput input = (UIInput) target;
System.out.println("id: " + input.getId());
System.out.println("value: " + input.getValue());
}
return VisitResult.ACCEPT;
}
});
By the way, you'd normally perform the validation with a normal Validator
on the UIInput
component or, in this particular case maybe better, a ValueChangeListener
. This allows for easier invalidation and message handling.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…