【问题标题】:inject ui:param into backend bean将 ui:param 注入后端 bean
【发布时间】:2013-12-24 11:53:44
【问题描述】:

我正在使用 jsf2 处理项目列表和维护组合页面。在此组合页面中,左侧面板应显示每行带有编辑按钮的项目行。单击编辑按钮时,右侧面板将需要显示所选项目的编辑页面。这需要通过 ajax 请求来完成。我正在尝试将右侧面板编辑页面放入包含文件中。因为用户可以在另一个地方访问此编辑页面。

我的问题如下: 这个编辑页面有它自己的后端 bean。此后端 bean 需要有关所选项目的一些信息,以便正确初始化和显示该项目。每次用户单击编辑按钮时,如何将所选项目信息传递给编辑页面的后端 bean?请注意,此编辑页面的显示需要作为 ajax 请求来完成。

谢谢

【问题讨论】:

  • 嗨 HockChai Lim,您在这里要求了解基本的 JSF-2 知识 - 任何教程都是最好的起点。 JSF-2 中的列表是例如通过 h:dataTable 完成,通过 h:commandButton 进行选择,并通过 f:ajax 使用合适的渲染属性进行 ajax-rerender。一旦你有一个可能的例子并遇到问题...... stackoverflow 就是要问的重点。

标签: jsf-2 facelets


【解决方案1】:

Hej HockChai Lim,

你可以使用这样的数据表:

<h:form id="myForm">
<h:dataTable id="myTable value="#{backingBeanA.items}" var="item">
<h:column>
 <f:facet name="header">ItemName</f:facet>
 <h:outputText value="#{item.name}">
</h:column>
<h:column>
 <h:panelGrid columns="2">
  <h:commandButton id="editBtn" action="#{backingBeanB.editItem(item)}" value="edit Item"/>
  <h:commandButton id="deleteBtn" action="#{backingBeanA.deleteItem(item)}" value="delete"/>
 </h:panelGrid>
</h:column>
</h:dataTable>
</h:form>

在 backingBeanB 中你需要方法

// saves the item in item2Edit 
// and returns the editPage.xhtml
// there you could get the item from
// backingBeanB with
// #{backingBeanB.item2Edit}
public String editItem(Item item) {
  this.item2Edit = item;
  return "editPage";

用于删除backingBeanA中的项目,也是方法

// saves the given item in item2Delete member and
// returns a deletion confirm page
public String deleteItem(Item item) {
  this.item2Delete = item;
  return "confirmItemDeletion";

或者你可以使用

<f:setPropertyListener target="#{backingBeanB.item}" value="item"/> 

在您的数据表中

希望这会有所帮助..

帕特里克

【讨论】:

  • 谢谢帕特里克。 是我正在寻找的。我最终必须在 commandlink 上使用 actionListener 而不是 action,它才能工作。我发现在使用动作时,setpropertylistener 将在动作之前执行。但是如果我使用 actionListner,setpropertylistener 会在 actionListner 之后执行。
猜你喜欢
  • 2013-08-31
  • 2015-04-15
  • 1970-01-01
  • 1970-01-01
  • 2013-02-16
  • 2014-11-25
  • 2011-09-09
  • 2013-06-25
  • 1970-01-01
相关资源
最近更新 更多