在错误消息之后将inputText值恢复为先前的值

问题描述 投票:0回答:1

我在片段中有2个表。

  1. 标题表
  2. 详细信息表(基于标题表显示的数据)

事情就是:标题表包含有序数量,详细信息表包含必须<=总排序数量(标题)的总分割数量(明细)。

场景:

一个。记录A在标题表中的订购数量为10

湾在详细信息表中有2个分割数量为5和4的记录,它们组合在一起是9,即<=有序数量(10)

要求:在提示错误消息后,将Detail表中的inputText列重置为上一个值的任何方法。

(这是为了防止用户转到Header表中的另一个记录并提交,然后提交Detail表中的无效值)

按钮代码:

public void saveButton(ActionEvent actionEvent) {
    int aQuantity=0;
    DCIteratorBinding orderDtl = ADFUtils.findIterator("OrderView4Iterator");
    if (orderDtl.getViewObject().getRowCount()>0){

    for(Row dtlRow: orderDtl.getAllRowsInRange()){
        System.out.println(dtlRow.getAttribute("OrderDtlIid"));
        aQuantity = aQuantity +  Integer.parseInt(dtlRow.getAttribute("Quantity").toString());
    }
    int bQuantity = Integer.parseInt(orderDtl.getCurrentRow().getAttribute("OrderQuantity").toString());

    if(aQuantity > bQuantity){
        errorMessage(null, "Error.");
     return;
    }
//then commit function}}}

列代码(详细信息表):

<af:column sortProperty="#{bindings.OrderView4.hints.Quantity.name}"
               filterable="true" sortable="false"
               headerText="#{bindings.OrderView4.hints.Quantity.label}"
               id="c3" width="182">
      <af:inputText value="#{row.bindings.Quantity.inputValue}"
                    label="#{bindings.OrderView4.hints.Quantity.label}"
                    required="#{bindings.OrderView4.hints.Quantity.mandatory}"
                    columns="#{bindings.OrderView4.hints.Quantity.displayWidth}"
                    maximumLength="#{bindings.OrderView4.hints.Quantity.precision}"
                    shortDesc="#{bindings.OrderView4.hints.Quantity.tooltip}"
                    id="it1" immediate="true" autoSubmit="true">
        <f:validator binding="#{row.bindings.Quantity.validator}"/>
      </af:inputText>
    </af:column>

单击该按钮后,该按钮进行了验证。但是这里的主要问题是当我转到另一个Header记录并单击saveButton并且Detail表中的先前错误数量也提交到数据库时,Detail表中的错误数量保持不变。

java jdeveloper
1个回答
0
投票

您可以创建自定义f:验证器,以便在用户键入时立即验证输入的数据,并且在字段无效时不允许用户使用您的按钮提交表单。

阅读更多:https://docs.oracle.com/cd/E15586_01/web.1111/b31973/af_validate.htm

当提交具有数据的表单时,浏览器将为其可编辑值属性绑定的每个UI组件向服务器发送请求值。在JSF应用请求值阶段期间解码请求值,并且解码的值本地保存在sumbittedValue属性中的组件上。如果值需要转换(例如,如果它显示为String类型但存储为DateTime对象),则在每个UI组件的过程验证阶段,数据将转换为正确的类型。

如果验证或转换失败,则生命周期将进入“渲染响应”阶段,并在页面上显示相应的错误消息。如果转换和验证成功,则启动更新模型阶段,并使用转换和验证的值更新模型。

发生验证或转换错误时,验证或转换失败的组件会在队列中放置关联的错误消息并使其自身无效。然后重新显示当前页面并显示错误消息。 ADF Faces组件提供了一种声明性地设置这些消息的方法。

在您的情况下,您的jsf将如下所示:

<af:column sortProperty="#{bindings.OrderView4.hints.Quantity.name}"
               filterable="true" sortable="false"
               headerText="#{bindings.OrderView4.hints.Quantity.label}"
               id="c3" width="182">
      <af:inputText value="#{row.bindings.Quantity.inputValue}"
                    label="#{bindings.OrderView4.hints.Quantity.label}"
                    required="#{bindings.OrderView4.hints.Quantity.mandatory}"
                    columns="#{bindings.OrderView4.hints.Quantity.displayWidth}"
                    maximumLength="#{bindings.OrderView4.hints.Quantity.precision}"
                    shortDesc="#{bindings.OrderView4.hints.Quantity.tooltip}"
                    id="it1" immediate="true" autoSubmit="true">
        <f:validator binding="#{YOUR_SCOPE.YOUR_BEAN.YOUR_CUSTOM_VALIDATOR}"/>
      </af:inputText>
    </af:column>

本教程也很有用:http://www.catgovind.com/adf/adf-custom-validator-example/

© www.soinside.com 2019 - 2024. All rights reserved.