【问题标题】:How can i create reusable backing structure?如何创建可重用的支持结构?
【发布时间】:2014-09-16 14:49:04
【问题描述】:

我正在使用 JSF 2.2 并尝试制作一些可重用的组件。
例如,其中之一应该是人员搜索对话框。例如:

子视图:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html">
    <h:inputText value="#{subviewBean.name}"  >
    <h:inputText value="#{subviewBean.surname}"  >
<h:commandLink title="OK" value="OK" action="subvieewBean.okClick/>
</ui:composition>

我正在尝试将此子视图包含在视图数量中,例如:

查看

<ui:composition xmlns="http://www.w3.org/1999/xhtml" />
      <h:outputText id="outputId" value="#{viewBean.subviewBean.name} #{viewBean.subviewBean.surname}" />
</ui.composition>

对应的豆子

@ManagedBean
@Named
@ViewScoped
public class SubviewBean{

    String name; //+ getter, setter
    String surname; //+ getter, setter

    ViewBean viewBean;

    public void okClick(){ 
        viewBean.okinsubviewClicked();
    }
}

@ManagedBean
@Named
@ViewScoped
public class ViewBean{

    SubviewBean subviewBean;
    okinsubviewClicked() {
        rerender(outputId)
}

这不是我的真实代码,更像是 JSF 风格的伪代码,旨在说明我的意图。

在按下“确定”按钮时,来自 searchBean 的数据应该以某种方式传输到 viewBean 或 view2Bean,它们可能与 viewBean 有一些相似之处,也可能没有。无论如何,我希望 subview 将姓名和姓氏转移到我想要的任何 bean,或者独立工作。不仅如此,主 bean 必须在子视图完成工作后重新渲染一些组件。有什么办法吗?

【问题讨论】:

    标签: jsf jakarta-ee jsf-2


    【解决方案1】:

    您可以使用&lt;f:param&gt;-tag

    <h:commandButton action="#{subviewBean.someAction}">
        <f:param name="name" value="#{subviewBean.name}" />
    </h:commandButton>
    

    ViewBean

    @ManagedProperty("#{param.name}")
    private String name;
    

    【讨论】:

      猜你喜欢
      • 2019-07-06
      • 1970-01-01
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      • 2020-11-11
      • 2018-11-05
      • 1970-01-01
      • 2018-02-23
      相关资源
      最近更新 更多