jsf清除表格 [英] jsf clearing the form

查看:178
本文介绍了jsf清除表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助.我是JSF的新手,我在项目中使用 JSF2 和richfaces.

我想清除刷新按钮中使用<f:ajax render="@form"/>的表单.我在该屏幕上有一个添加按钮,该按钮添加了一条记录,然后单击刷新",然后转到默认页面.但是当我再次输入记录时,我之前输入的那些值仍保留在表单字段中.

有人可以帮我解决这个问题吗?

解决方案

假设您说我点击刷新"是指浏览器的刷新按钮,那么如果您错误地放置了包含视图作用域数据的bean,则可能会发生这种情况.在会话范围内.然后,您基本上将重用与先前提交表单相同的bean.将bean放在视图范围而不是会话范围中应该可以解决此问题.当您导航到其他页面或触发新请求时(如通过单击浏览器的刷新按钮),视图作用域结束.

另请参见:


更新,如果由于设计不良而限制使用会话范围,那么您可能想通过

来解决这个问题

<f:event type="preRenderView" listener="#{sessionScopedBeanWhichShouldActuallyBeViewScoped.resetModel}" />

使用

public void resetModel() { 
    if (!FacesContext.getCurrentInstance().isPostback()) {
        model = null;
    }
}

这将清除每个GET请求的模型.但是,不管这种黑客攻击如何,当最终用户在同一会话中的不同浏览器选项卡/窗口中打开同一视图时,您仍然会遇到严重的问题.

正确的解决方案是将bean置于视图范围而不是会话范围,如先前所述.

I need help. I'm new to JSF and im using JSF2 and richfaces in my project.

I want to clear the form for which I'm using <f:ajax render="@form"/> in refresh button. I have an ADD button on that screen which adds one record and I hit refresh then it's going to the default page. But when I once again go to enter a record then those values which I entered earlier remain in the form fields.

Can anyone please help me out with this issue?

解决方案

Assuming that you mean the browser's refresh button when you say "I hit refresh", then that can happen if you've incorrectly placed the bean holding view scoped data in the session scope. You're then basically reusing the very same bean as the form is previously been submitted to. Putting the bean in the view scope instead of the session scope should fix this problem. The view scope ends when you navigate to a different page or fires a new request (as by hitting browser's refresh button).

See also:


Update if you're due to bad design restricted to using session scope, then you might want to hack this around by a

<f:event type="preRenderView" listener="#{sessionScopedBeanWhichShouldActuallyBeViewScoped.resetModel}" />

with

public void resetModel() { 
    if (!FacesContext.getCurrentInstance().isPostback()) {
        model = null;
    }
}

This will clear the model on every GET request. However, regardless of this hack, you'll still run into serious problems when the enduser opens the same view in a different browser tab/window within the same session.

The right solution is to put the bean in the view scope instead of the session scope, as said earlier.

这篇关于jsf清除表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆