java JSF/primefaces - 将属性传递给对话框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6822068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSF/primefaces - passing property to dialog
提问by Smolda
I currently trying to pass some data from datatable to dialog and then confirm some action. My problem is that passing the bean to dialog works fine but when I try to save it by clicking the save button it appears to be null.
我目前正在尝试将一些数据从数据表传递到对话框,然后确认一些操作。我的问题是将 bean 传递给对话框工作正常,但是当我尝试通过单击保存按钮保存它时,它似乎为空。
code:
代码:
<p:column>
<p:commandButton value="Mark" update="showPlayers:display" oncomplete="userDialog.show()" >
<f:setPropertyActionListener value="#{user}" target="#{manageUser.selectedUser}" />
</p:commandButton>
</p:column>
...
<p:dialog header="Mark" widgetVar="userDialog" resizable="true" id="userDlg"
width="400" showEffect="fade" hideEffect="explode" modal="true">
<h:panelGrid id="display" columns="2"
<!-- this below works fine -->
<h:outputText value="#{manageUser.userSelected.email}"/>
<p:commandButton ajax="false" value="Save" actionListener="#{manageUser.addNewFeature}" oncomplete="userDialog.hide()" />
</h:panelGrid>
</p:dialog>
When I try in method addNewFeature
work with bean userSelected it resolved to null and throw NullPointerException. I don't actually know where I lost reference to this instance. This bean is request scoped.
当我尝试addNewFeature
使用 bean userSelected 的方法时,它解析为 null 并抛出 NullPointerException。我实际上不知道我在哪里丢失了对这个实例的引用。这个 bean 是请求范围的。
Thanks for any comments or answers.
感谢您的任何评论或答案。
回答by Maddy
- A @ViewScoped bean will live as long as you return null or void from the action methods (and thus navigate back to the same view).
- A @RequestScoped bean will be garbaged by end of every request and recreated on every new requestm hereby losing all original properties.
- 只要您从操作方法返回 null 或 void(从而导航回同一视图),@ViewScoped bean 就会存在。
- @RequestScoped bean 将在每个请求结束时被垃圾处理,并在每个新请求上重新创建,从而丢失所有原始属性。
Try change scope to view.
尝试更改范围以查看。
http://balusc.blogspot.com/2010/06/benefits-and-pitfalls-of-viewscoped.html
http://balusc.blogspot.com/2010/06/benefits-and-pitfalls-of-viewscoped.html