1

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Shishigami
  • 441
  • 3
  • 7
  • 20
  • Please do not use Stack Overflow question editor as code editor. Edit (and test!) it in a true editor and then copypaste code unmodified. – BalusC Sep 10 '13 at 10:52

2 Answers2

7

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)

Daniel
  • 36,833
  • 10
  • 119
  • 200
  • 1
    Thanks a lot, the ajax event did the trick. I mixed up value and label while typing the question, luckily I had it right in my actual code. – Shishigami Sep 10 '13 at 08:36
  • your link "p:ajax enables ajax behavior on any JSF component" refers to a not existing page. please change it – adranale Feb 03 '16 at 11:29
1

Lets give your components ids:

<h:form id="someForm">
  <p:inputText id="first" value="#{myController.selectedBean.text}" />
  <p:inplace id="second" editor="true" value="#{myController.selectedBean.text}">
    <p:inputText id="third" value="#{myController.selectedBean.text}" />
  </p:inplace>
</h:form>
  1. According to the Primefaces Documentation 3.5 the component p:inplace has no attribute called value.

  2. Do you submit the form someForm when changing the value of first? Otherwise the updated values from first won't be passed to MyController and MyBean. p:inplace submits the values automatically whereby you have to do it yourself it you use the standard p:inputText.

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
Manuel
  • 3,828
  • 6
  • 33
  • 48