English 中文(简体)
价值在《共同财产法》2 的标本被清除后仍为形式领域。
原标题:Value remains in form field after it is cleared in bean in JSF2

In my JSF2 application, I have "Clear" button, which is supposed to clear all the fields. However, it doesn t always work.

My page fragment:

<h:form id="bi">
  <h:inputText value="#{bean.entity.firstname}" />
  <h:inputText value="#{bean.entity.surname}" />

  <h:commandButton value="Clear" immediate="true" action="#{bean.clear}">
    <f:ajax render="bi" />
  </h:commandButton>
  <h:commandButton value="Submit" action="#{bean.submit}" />
</h:form>

clear( methods in my bean:

public void clear() {
  entity = new Entity();
}

If I enter values in the fields, and click "Clear", everything is cleared as expected. However, consider such scenario: 1. Enter value only in one field (both are required by JSR303 annotations on entity). 2. Click "Submit". Error message appears. 3. Click "Clear".

残值不变。 为什么没有清除地雷?

此外,如果我直截了当,把“Clear”点击回外地。 我检查说,在点击“Clear”纽子之后,部分答复涉及浏览器。 我怀疑它有某种看法。

此外,如果我在实地添加<条码>validator=”#{bean.validate}“,则该编码即进入这一验证。 即使纽特州有<代码>mmediate=“true”属性。 为什么? 是否应当立即对纽特州om进行验证?

最佳回答

您现在就是一个或多或少人熟知的问题,涉及更新已经证实的内容。

这个职位相当老,但依然具有相关性:http://ishabalov.blogspot.com/2007/08/sad-story-about-uiinput.html”rel=“nofollow”http://ishabalov.blogspot.com/2007/08/sad-story-about-uiinput.html。

The community Creat for A4J in JSF 1.2 listed here:

但不幸的是,这并不直接在第二号共同法中工作,而就你而言,它根本就不工作了,因为它具体体现了A4J。 然而,这可能是灵感的来源。

基本来说,你们需要走大树,并清除树脂。 试不起的是,确切地说,你将重新投标的部件状况。 但是,如果你的具体应用或网页能够容忍的话,你可以采取强硬的做法,而且只是简单明了。

问题回答

我不得不避免提交或采取行动,使表格适当清晰。 我使用了一种无效信条方法。

但是,当时我面临有条件需要的导航问题,这种导航通常是用强硬的方法从行动中进行的。 我利用外部参考文献(redirect)()来完成我从以下几个方面学到的内容:

https://stackoverflow.com/questions/6208037/jsf-post-range-handling-redirect> JSF 员额例外处理——Redirect

JSF Navigation redirect to previous page

我的网页代码:

            <p:commandButton value="Login" update=":loginForm"
                            actionListener="#{loginBean.login}"/>

我的美术法典:

public void login() {
    RtsLDAPAD laLdap = new RtsLDAPAD();
    boolean lbAuthenticated = false;
    try
    {           
        lbAuthenticated = laLdap.login(userName, password);
        System.out.println(
            "The Result is " + lbAuthenticated + " for " + userName);
    }
    catch (Exception aeRTSEx)
    {
        aeRTSEx.printStackTrace();
    }

    if (lbAuthenticated) {
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("taskform.jsf");
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {

        FacesContext facesContext = FacesContext.getCurrentInstance();
        facesContext.addMessage(null,
                new FacesMessage("Login failed for " + userName + "."));
        UIViewRoot uiViewRoot = facesContext.getViewRoot();

        HtmlInputText inputText = null;
        Password pwd = null;
        inputText = (HtmlInputText) uiViewRoot.findComponent("loginForm:username");
        inputText.setSubmittedValue(null);
        inputText.setValue(null);
        inputText.setLocalValueSet(false);
        inputText.setValid(true);

        pwd = (Password) uiViewRoot.findComponent("loginForm:password");
        pwd.setSubmittedValue(null);
        pwd.setValue(null);
        pwd.setLocalValueSet(false);
        pwd.setValid(true);

        userName = null;
        password = null;            
    }
}




相关问题
Bind Button.IsEnabled to custom validation with XAML?

I am sorry I didn t know how to title my question any better, you name it if you got a good 1. I have an entity Contact. this person has navigation properties: Address, Phones (A collection of Phone)....

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

Rails 101 | validates_currency?

I ve searched high and low, but I could not find a solution, to what I think seems like a very common task. In a form I want to have a text input that accepts currency strings (i.e. $1,000,000 or ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签