2017-03-04 70 views
1

我需要重新設置表單域和清除表單值的onload。 不過我用 -復位形式值的onload在bootsfaces

public void refresh() { 
    FacesContext context = FacesContext.getCurrentInstance(); 
    Application application = context.getApplication(); 
    ViewHandler viewHandler = application.getViewHandler(); 
    UIViewRoot viewRoot = viewHandler.createView(context, context 
    .getViewRoot().getViewId()); 
    context.setViewRoot(viewRoot); 
    context.renderResponse(); //Optional 
    } 

上面的代碼工作,但是當我在使用領域在panelGroup中輸入值,它不工作。

<h:panelGroup> 
<ui:repeat value="#{formDynAttrbBean.vals}" var="values"> 
    <b:panelGrid columns="6" cellspacing="4"> 
     <b:inputText id="label" value=""> 
     </b:inputText> 
     <b:selectOneMenu value=""> 
      <f:selectItem itemLabel="SelectType" itemValue="" /> 
      <f:selectItems value="" /> 
     </b:selectOneMenu> 
     <b:selectBooleanCheckbox value="" /> 
     <b:commandButton actionListener="#{form.types}" /> 
    </b:panelGrid> 
</ui:repeat> 
<b:commandButton tooltip="Add new attribute" tooltip-position="bottom" 
    iconAwesome="plus" actionListener="#{form.add}" update="@form" /> 
<tr /> 
<b:commandButton value="Save" ajax="true" 
    actionListener="#{form.submit}" update="@form" /> 
<tr /> 
<b:commandButton type="reset" action="#{formController.refresh}" 
    value="Reset"> 
</b:commandButton> 
</h:panelGroup> 

刷新功能是不是在這種情況下工作時,我進入panelGroup中和重複字段的值。 我只是一個初學者boots boots。請告訴我一個方法。提前告訴我。

回答

1

有一些方法可以清除表單的輸入域。例如,JSF 2.2有resetValues="true"屬性(見the article of Michael Kurz(可能不是由BootsFaces實現)。另一種選擇是使用<b:commandButton type="reset">

但我不知道你爲什麼要在客戶端上的值重置?你要清楚他們,因爲他們展示一些「髒」(即修改)後端豆。恕我直言,更好的方法是創建一個新的空後端豆。

+0

三江源....但是,你能給我們解釋程序如何在清空豆值復位? – Spandana

+0

你已經有了一個'refresh'方法,對嗎?我只是Bean的每一個屬性手動設置爲空或對象的新實例,如果屬性不是原始數據類型。順便說一句,使用這種方法,你必須刪除'type =「reset」'位。它阻止了調用bean方法。 –