Arash Amiri
Arash Amiri

Reputation: 13

How to access inputtext binding in jsf

I have the following problem and I could not find a solution anywhere.

I have the following code:

<h:inputText id="username" value="#{registrationBB.userName}" binding="#{userNameToConfirm}"/>

and later on:

<h:inputSecret id="confirmed-password" value="#{registrationBB.userPasswordConfirmed}">
  <f:validator validatorId="usernameNotInPasswordValidator"/>
  <f:attribute name="username" value="#{userNameToConfirm.value}" />
</h:inputSecret>

The inputText is bound to #{userNameToConfirm} (which is not a property in any backingbean) and later this binding is used in the password validator.

This all works well.

But, the form that these fields are on contains a "Reset" button, that should empty all fields on the form.

When the reset button is clicket, all properties in the registrationBB are emptied and the following code is called:

getViewRoot().getChildren().clear();

But, the username will never be empty, because it will always be set by the value in the "#userNameToConfirm" binding.

My question is: How can I access this binding and delete in the faces back-end?

We use jsf version 1.2.

regards, arash

Upvotes: 1

Views: 1793

Answers (1)

BalusC
BalusC

Reputation: 1108557

Let the reset button reload the page instead.

<h:commandButton value="Reset" onclick="location.reload(true)" />

Or by a <navigation-case> with a <redirect>.

<h:commandButton value="Reset" action="reloadPagename" />

with

<navigation-rule>
    <navigation-case>
        <from-outcome>reloadPagename</from-outcome>
        <to-view-id>/pagename.jsf</to-view-id>
        <redirect />
    </navigation-case>
</navigation-rule>

Upvotes: 1

Related Questions