在靴面

时间:2017-03-04 11:26:47

标签: java reset bootsfaces

我需要重置表单字段并清除表单值onload。 不过我用过 -

    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和重复字段中输入值时,刷新功能在这种情况下不起作用。 我只是靴子的初学者。请建议我一个方法。提前做好。

1 个答案:

答案 0 :(得分:1)

有多种方法可以清除表单的输入字段。例如,JSF 2.2具有resetValues="true"属性(请参阅the article of Michael Kurz(可能未由BootsFaces实现)。另一种选择是使用<b:commandButton type="reset">

但我想知道你为什么要重置客户端的值?你必须清除它们,因为它们显示一些“脏”(即修改过的)后端bean。恕我直言,更好的方法是创建一个新的空后端bean。