【问题标题】:Reset form values onload in bootsfaces在 bootsfaces 中重置表单值 onload
【发布时间】:2017-03-04 11:26:47
【问题描述】:

我需要重置表单域并清除加载的表单值。 不过我用过-

    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>

当我在面板组和重复字段中输入值时,刷新功能在这种情况下不起作用。 我只是 bootsfaces 的初学者。请建议我一种方法。提前谢谢你。

【问题讨论】:

    标签: java reset bootsfaces


    【解决方案1】:

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

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

    【讨论】:

    • Thankyou.... 但是您能否以编程方式解释如何在重置时清空 bean 中的值?
    • 你已经有了refresh 方法,对吧?如果属性不是原始数据类型,我只需手动将 bean 的每个属性设置为 null,或者设置为对象的新实例。顺便说一句,使用这种方法,您必须删除 type="reset" 位。它可以防止调用 bean 方法。
    猜你喜欢
    • 1970-01-01
    • 2019-07-28
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多