ADF:弹出窗口,对话框和输入组件

在本文中,当我们有一个af:popup包含af:dialog并在其中包含输入组件时,我想着重介绍一个非常常见的用例。 在实现此用例时,需要注意一些陷阱。

让我们考虑一个简单的示例:

<af:popup id="p1" contentDelivery="lazyUncached">
          
  <af:dialog id="d2" title="Dialog" >
     <af:inputText value="#{TheBean.firstName}" label="First Name" id="it1"/>
     <af:inputText value="#{TheBean.lastName}" label="Last Name" id="it2"/>
  </af:dialog>
  
</af:popup>

这里最有趣的是弹出窗口的属性contentDelivery ,该属性设置为lazyUncached 。 这样可以防止弹出窗口缓存提交的输入值,并强制其从每个请求的模型中获取值,而不是使用缓存中的值。

让我们将示例变得更加复杂。 在姓氏的设置器中,我们将引发一个异常:

public void setLastName(String lastName) throws Exception {        
    this.lastName = lastName;        
    throw new Exception("This last name is bad");
}

因此,显然,如果我们尝试提交对话框,则会得到以下信息:

屏幕截图2014年8月4日下午7.09.13
输入值不能提交给模型,它们将存储在输入组件的局部值中。 即使我们按“ 取消”按钮,也不会清除这些本地值,并且在子序列请求期间将使用这些值。 为了防止这种行为,我们必须将弹出窗口的resetEditableValues属性设置为whenCanceled 。 像这样:

<af:popup id="p1" contentDelivery="lazyUncached"
                  resetEditableValues="whenCanceled">

  <af:dialog id="d2" title="Dialog" >
     <af:inputText value="#{TheBean.firstName}" label="First Name" id="it1"/>
     <af:inputText value="#{TheBean.lastName}" label="Last Name" id="it2"/>
  </af:dialog>  
  
</af:popup>

让我们来看一个带有自定义按钮的af:dialog的示例:

<af:popup id="p1" contentDelivery="lazyUncached"
                  resetEditableValues="whenCanceled"
                  binding="#{TheBean.popup}">

  <af:dialog id="d2" title="Dialog" type="none">
     <af:inputText value="#{TheBean.firstName}" label="First Name" id="it1"/>
     <af:inputText value="#{TheBean.lastName}" label="Last Name" id="it2"/>
     <f:facet name="buttonBar">
        <af:panelGroupLayout layout="horizontal" id="pgl1">
          <af:button text="Ok" id="b2" 
                     actionListener="#{TheBean.buttonActionListener}"/>
          <af:button text="Cancel" id="b3" immediate="true"
                     actionListener="#{TheBean.buttonActionListener}"/>
        </af:panelGroupLayout>  
     </f:facet>

  </af:dialog>  
  
</af:popup>

因此,使用以下actionListener有两个自定义按钮“ Ok”“ Cancel”

public void buttonActionListener(ActionEvent actionEvent) {
    getPopup().hide();
}

在这种情况下, resetEditableValues不起作用,并且在按“ 取消”按钮时不会清除输入组件的本地值。 有几个选项可以解决此问题。

第一个是将af:resetListener添加到“取消”按钮:

<af:button text="Cancel" id="b3" immediate="true"
                     actionListener="#{TheBean.buttonActionListener}">
               <af:resetListener type="action"/>
          </af:button>

第二个选项是取消弹出窗口,而不仅仅是将其隐藏在“取消”按钮动作侦听器中:

<af:button text="Ok" id="b2" 
             actionListener="#{TheBean.buttonActionListener}"/>
  <af:button text="Cancel" id="b3" immediate="true"
             actionListener="#{TheBean.cancelButtonActionListener}"/>
public void cancelButtonActionListener(ActionEvent actionEvent) {
   getPopup().cancel();
}

而已!

翻译自: https://www.javacodegeeks.com/2014/08/adf-popup-dialog-and-input-components.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值