0

I'm trying to write a generic method to clear all fields content in a JSF component, in HTML, e.g. a panelGroup. If I have a panel group with fields A, B, C, I wanna per my view find the related fields in the backing bean and set it to null in the server side, Is it possible? For now I have this method:

public String clear(final String parentComponentId) {
    UIViewRoot view = FacesContext.getCurrentInstance().getViewRoot();
    UIComponent fc = view.findComponent(parentComponentId);
    if (null != fc) {
        List<UIComponent> components = fc.getChildren();
        for (UIComponent component : components) {
            if (component instanceof UIInput) {
                UIInput input = (UIInput) component;
                input.resetValue();
            }

        }
    }
    return null;
} 

But I think that the UIInput.resetValue() does not set the value on the server side...

PS: Just trying to put it more clear, the final goal is to set all components that are not rendered (rendered="false") automatically as null in the backing bean.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
chr0x
  • 1,151
  • 3
  • 15
  • 25
  • What a strange approach. Why not just let the reset button/action reload the page by GET? It'll create a brand new and fresh view all by itself. – BalusC Apr 27 '15 at 17:04
  • Hi @BalusC , the problem is that I have various fields with partialSubmit setted, so I'm having to set these as null in the server. In this case, if I only reload the page, the content will still be there. :( – chr0x Apr 27 '15 at 17:21
  • So you're using PrimeFaces? Have you considered just using its ``? Is this Q&A then acceptable as dupe? http://stackoverflow.com/questions/21179403/jsf2-pf-4-how-to-update-component-when-process-this/ By the way, if the values are still there on page reload, then it could mean that the bean is incorrectly placed in session scope, or that you didn't disable browser caching of pages. – BalusC Apr 27 '15 at 17:21
  • Yes, I'm using PrimeFaces, but I didn't knew about p:resetInput. I'll read about it now. – chr0x Apr 27 '15 at 17:23

0 Answers0