在 Ajax 请求后使用 JSF 2.0 调用 RenderResponse 保留文本框数据
当我使用immediate = true执行ajax操作时,如何保留文本框值?我需要渲染整个表单。我想在执行 ajax 操作时跳过验证和更新模型阶段。我尝试在 ajax 操作调用的方法末尾使用 FacesContext.getCurrentInstance().renderResponse() 但它不起作用。旧值出现在文本框中,或者某些文本框中的某些数据被清除。我还不想更新支持 bean。
我想要做的是保留用户在文本框中填写的信息。我使用的 Ajax 按钮动态添加更多文本框,并在 ajax 按钮中设置渲染属性,以渲染整个页面(我需要执行完整渲染)。在我使用 ajax 操作调用的方法内部,我有“FacesContext.getCurrentInstance().renderResponse();”
按钮代码是:
<h:commandButton id="btnAdd" value="Add" type="button">
<f:ajax event="click" execute="@form" render=":form" listener="#{ManagedBean.add()}"/>
</h:commandButton>
侦听器操作是:
public void add() {
Person p = new Person();
ManagedBean.getPeople().add(p);
FacesContext.getCurrentInstance().renderResponse();
}
我有一个 ui:repeat 要在“人员”列表中迭代,文本框的代码是:
<ui:repeat value="#{ManagedBean.people}" var="currentPerson" varStatus="i">
<h:inputText id="p" readonly="false" label="Person" value="#{currentPerson.name}" >
</h:inputText>
</ui:repeat>
我正在调试 JSF 阶段,我得到:
[2/7/12 15:06:33:584 CST] 0000002f SystemOut O START PHASE RESTORE_VIEW 1
[2/7/12 15:06:34:375 CST] 0000002f SystemOut O END PHASE RESTORE_VIEW 1
[2/7/12 15:06:34:981 CST] 0000002f SystemOut O START PHASE APPLY_REQUEST_VALUES 2
[2/7/12 15:06:35:553 CST] 0000002f SystemOut O END PHASE APPLY_REQUEST_VALUES 2
[2/7/12 15:06:36:089 CST] 0000002f SystemOut O START PHASE RENDER_RESPONSE 6
[2/7/12 15:06:44:364 CST] 0000002f SystemOut O END PHASE RENDER_RESPONSE 6
有没有办法拉文本框中的数据并在 ajax 调用后在视图中再次设置它们?谢谢。
How can I preserve the textboxes values when I perform an ajax action with immediate = true? I need to render the entire form. I want to skip the validations and update model phases when the ajax action is performed. I've tried using FacesContext.getCurrentInstance().renderResponse() at the end of the method that is invoked by the ajax actions but it doesn't work. Old values appear in the textboxes or some data is cleared in some textboxes. I don't want to update the backing bean yet.
What I want to do is to keep the information that the user is filling in the textboxes. The Ajax button that I use adds dynamically more textboxes and I set render attribute, in the ajax button, to render the entire page (I need to do a complete render). Inside the method I call with the ajax action I have "FacesContext.getCurrentInstance().renderResponse();"
the button code is:
<h:commandButton id="btnAdd" value="Add" type="button">
<f:ajax event="click" execute="@form" render=":form" listener="#{ManagedBean.add()}"/>
</h:commandButton>
And the listener action is:
public void add() {
Person p = new Person();
ManagedBean.getPeople().add(p);
FacesContext.getCurrentInstance().renderResponse();
}
I have an ui:repeat to iterate in the "people" List and the code of the textbox is:
<ui:repeat value="#{ManagedBean.people}" var="currentPerson" varStatus="i">
<h:inputText id="p" readonly="false" label="Person" value="#{currentPerson.name}" >
</h:inputText>
</ui:repeat>
I was debbuging the JSF phases and I got:
[2/7/12 15:06:33:584 CST] 0000002f SystemOut O START PHASE RESTORE_VIEW 1
[2/7/12 15:06:34:375 CST] 0000002f SystemOut O END PHASE RESTORE_VIEW 1
[2/7/12 15:06:34:981 CST] 0000002f SystemOut O START PHASE APPLY_REQUEST_VALUES 2
[2/7/12 15:06:35:553 CST] 0000002f SystemOut O END PHASE APPLY_REQUEST_VALUES 2
[2/7/12 15:06:36:089 CST] 0000002f SystemOut O START PHASE RENDER_RESPONSE 6
[2/7/12 15:06:44:364 CST] 0000002f SystemOut O END PHASE RENDER_RESPONSE 6
It is there a way to pull the data from the textboxes and set it again to them in the view after the ajax call? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为 people 中的 people 使用包装类。然后您可以让 JSF 调用 setter,而原始的 person 对象将不会被触及。
磁力,
米洛·范德泽
you could use a wrapper class for the persons in people. Then you can let JSF call the setters and the original person objects wont' be touched.
MAG,
Milo van der Zee