jsfprimefacesin-place-editor

<p:inputText> value not updated in model on change


I have a form that lets me edit a list of beans (one at a time), using buttons I can switch between the beans.

Keeping it simple :

public class MyBean {
   private String text;
}

public class MyController {
   private List<MyBean> availableBeans = new ArrayList<MyBean>(); // has five MyBeans with random text
   private MyBean selectedBean; // initialized with first element of list

   private int index = 0;

   public void nextBean() { index++; }
   public void previousBean() { index--; }

   private void refreshBean() { selectedBean = availableBeans.get(index); }
}

For the html part I have something like

<h:form id="someForm">
   <!-- stuff -->

    <p:inputText value="#{myController.selectedBean.text}" />

    <p:inplace editor="true" label="#{myController.selectedBean.text}" >
        <p:inputText value="#{myController.selectedBean.text}" />
    </p:inplace>

   <!-- more stuff-->
</h:form>

If I change the text inside the inplace tag, the variable in myBean will be updated just fine, but If I only use inputText the bean will still have the old value, even if I change it on the webpage. Why is that?


Solution

  • Its because the p:inplace editor="true" implicitly submits the value to the server while <p:inputText does not do it implicitly,

    You can solve it in several ways

    1) add submit button like <p:commandButton to submit the value from p:inputText

    2) use p:ajax event="keyup" or event="change",inside p:inputText

    also take a look at the showcase p:ajax enables ajax features on supported components.

    p.s , remove the value attribute from the p:inplace (there is no such attribute in p:inplace)