2017-03-04 18 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方法。 –