Shi*_*ami 1 jsf in-place-editor primefaces
我有一个表单,让我可以编辑一个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); }
}
Run Code Online (Sandbox Code Playgroud)
对于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>
Run Code Online (Sandbox Code Playgroud)
如果我更改inplace标签内的文本,myBean中的变量将被更新,但是如果我只使用inputText,那么即使我在网页上更改了bean,bean仍将具有旧值.这是为什么?
因为它p:inplace editor="true"隐式地将值提交给服务器而<p:inputText不是隐式地,
您可以通过多种方式解决它
1)添加提交按钮,如<p:commandButton提交值p:inputText
2)使用p:ajax event="keyup"或event="change",内部p:inputText
另请参阅showcase p:ajax在支持的组件上启用ajax功能.
ps,value从中删除属性p:inplace(没有这样的属性p:inplace)
| 归档时间: |
|
| 查看次数: |
13651 次 |
| 最近记录: |