[英]<p:inputText> value not updated in model on change
我有一個表格,可讓我使用可以在各個bean之間切換的按鈕來編輯一個bean列表(一次一個)。
保持簡單:
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); }
}
對於html部分,我有類似
<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>
如果我更改了inplace標記內的文本,則可以很好地更新myBean中的變量,但是,如果我僅使用inputText,即使我在網頁上進行了更改,bean仍將具有舊值。 這是為什么?
這是因為p:inplace editor="true"
隱式將值提交給服務器,而<p:inputText
不隱式地將值提交給服務器,
您可以通過多種方式解決它
1)添加<p:commandButton
類的提交按鈕,以從p:inputText
提交值
2)在p:inputText
內部使用p:ajax event="keyup"
或event="change"
還可以看一下展示櫃p:ajax在支持的組件上啟用ajax功能。
PS,刪除value
從屬性p:inplace
(存在沒有這樣的屬性p:inplace
)
讓我們給您的組件id
:
<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>
根據Primefaces文檔3.5 ,組件p:inplace
inplace沒有名為value
屬性。
更改first
的值時,是否提交someForm
表單? 否則,從first
的更新值將不會傳遞給MyController
和MyBean
。 p:inplace
自動提交值,因此您必須使用標准p:inputText
自己進行操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.