简体   繁体   中英

input.setValid(false) does not have any effect when component is inside <ui:repeat>

I need to mark inputText field generated using ui:repeat as invalid. I am able to do it for normal input fields by using following code in bean:

 UIComponent root = context.getViewRoot();
 UIInput inputFieldObj = obj.findComponent(root, id);
 inputFieldObj .setValid(false);

The above code is working, however when I try to get the components that are generated using ui:repeat. Its not marking the textfield as invalid.

So for below code its working:

<p:inputText id="txtEmpId12" /> 

But for this its not:

<ui:repeat>
    <p:inputText id="txtEmpId" />   
</ui:repeat>

This is because in your scenario component tree contains only one input. Ui:repeat renders inputs on render phase. As a workaround you could use c:forEach . In this case component tree will contain all inputs. But I don't like this approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM