h:inputText not updating properly ?

UI Components for JSF
Post Reply
viulian
Posts: 3
Joined: 28 Nov 2010, 22:42

28 Nov 2010, 23:05

Hello,

I'm trying the following basic scenario:

1) A Request scoped bean:

Code: Select all

    <managed-bean>
        <managed-bean-name>postsBean</managed-bean-name>
        <managed-bean-class>com.hexbinama.hdyf.beans.PostsBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
2) bean content:

Code: Select all

public class PostsBean {

    private String sayHello;
    private static int i = 0;

    public PostsBean() {
        if (log.isDebugEnabled()) {
            log.debug("Created Bean.");
        }

        setSayHello((i++) + "");
    }

    public void sendAction(ActionEvent event) {
    }

    public String getSayHello() {
        return sayHello;
    }

    public void setSayHello(String sayHello) {
        this.sayHello= sayHello;
    }
3) the following piece of JSF:

Code: Select all

        <h:form prependId="false">

            <h:outputText id="label" value="#{postsBean.sayHello}" />
            <h:inputText id="sayHello" value="#{postsBean.sayHello}" />
            
            <p:commandButton value="Send" actionListener="#{postsBean.sendAction}" update="sayHello label"/>

        </h:form>
As you can see, both the h:outputText and h:inputText share the same value, the bean's sayHello member. Also, the bean's constructor increments the static variable i.

Steps:
a) I start a new session on the browser and then keep pressing F5, both the text as well as the input text will increment value [as expected].
b) I type something inside the input text, click Send. Both label and input text show the new value that was typed.
c) I press F5 again - label shows the incrementing values again, but input text remains 'stuck' on the value that I typed at point b).

I expect it to also start to show incrementing numbers.

Also, a "shorter" version is available:
a) Start new session in browser. Keep pressing F5 and confirm both label and input text show incrementing value. Is normal, scope is request, new bean is created on each F5.
b) type anything in input text. No need to press "Send" button. Just change the value shown in the input text and then press F5. Only label updates, input text remains with the value that is typed within. Expected: it should also show the same value that the label is showing.

Any idea why this happens ?

Thank you,

callahan
Posts: 768
Joined: 27 May 2010, 22:52

28 Nov 2010, 23:50

After F5 is hit, the browser is automatically "reentering" the value that was previously entered. If you look at the network responses with Firebug, I think you'll see the data you expect to see in the browser, but don't!

viulian
Posts: 3
Joined: 28 Nov 2010, 22:42

30 Nov 2010, 04:00

You were right, I had to disable the autocomplete for the fields ( <h:inputText ... autocomplete="off" />) to fix the F5 behavior.

Thanks!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 8 guests