繁体   English   中英

如何从ICEfaces模态弹出窗口调用托管bean?

[英]How do I invoke managed bean from an ICEfaces modal popup?

我正在使用Eclipse Luna EE,Tomcat v7.0和ICEFaces 3.2

我有一个用于标签打印的表格,用户可以输入信息,例如项目编号,项目名称和标签类型。 然后,用户提交表单。 这会将信息发送到ZPL字符串中的标签打印机,然后打印机打印出该物品的正确标签。 这一切都没问题。

如果值较高(生产中为100+),则该表格将检查打印数量。 如果打印数量超过某个值(> 2.仅用于测试目的),则将“ testFlag”布尔值设置为true,显示模式框并设置错误标志,以使打印命令不执行。

模态框使用可用/否按钮询问用户是否输入了正确的数量。

printUI和模式弹出窗口位于相同的<ice:form>元素内,如果testFlag设置为true,则呈现弹出框并可见。

问题:当我单击模式框中的“是”按钮时,它不执行我分配给它的操作( System.out.println("Yes Button!") )。 模式框关闭,没有任何反应。

然后,我可以重新提交表单,并且再次出现模态框,然后单击“是”,没有任何反应。

如果我将数量更改为2并提交,则执行打印命令没有问题。

我猜想这是处理会话方式的问题。

问题:如何获得模态框上的“是”按钮来执行所需的代码?

我试过了:使用<ice:commandLink><h:button><h:commandButton><h:commandLink>

在单独的<ice:form>标记中包含模式弹出窗口和表单(这刷新了会话并删除了所有输入的数据)。

使用一个actionListener

包含以下形式的代码:

<h:body>
    <div id="surround">
        <ice:form id="test" prependId="false">
            <ui:include src="./printUI.xhtml" />
            <ui:include src="./printQtyPopup.xhtml" />
        </ice:form>
    </div>
</h:body>

printQtyPopup.xhtml

    <ui:composition>
        <ice:panelPopup modal="true" visible="#{validateBean.testFlag}" rendered="#{validateBean.testFlag}">
            <f:facet name="header">
                <ice:outputText value="Print Quantity Check" />
            </f:facet>
            <f:facet name="body">
                <ice:panelGrid>
                    <ice:outputText value="You selected a print quantity of: #{validateBean.printAmount}" />
                    <ice:outputText value="Is this correct?" />
                    <ice:panelGroup>
                        <ice:commandButton value="No" />
                        <ice:commandButton value="Yes" action="#{validateBean.checkQtyYes}" />
                    </ice:panelGroup>
                </ice:panelGrid>
            </f:facet>
        </ice:panelPopup>
    </ui:composition>

相关的ValidateBean.java代码

    public void validate() { //validation checks are carried out when the user clicks "Print" on the printUI.
        if (!errorFlag && checkQty && printQty > 2) {
            testFlag = true;
            errorFlag = true;
            System.out.println("Qty Check Modal");
        }

        if (!errorFlag) {
            if (printQty > 0) {
                initialiseString();

                initialisePrinter();

                clear();
            } else {
                printQty = 0;
                errorMessage = true;
                quantityInvalid = true;
                errorFlag = true;
            }
        }
    }

    public void checkQtyYes() {
        System.out.println("Yes Button!");
    }

我找到了替代方案。

我删除了模式弹出窗口以及与其链接的所有代码。

我在表单末尾添加了<ice:panelConfirmation> 仅当打印数量超过我设置的任何数量时,才会渲染该图像。

我通过在onblur="submit()"打印数量<h:inputText>上使用valueChangeListener="#{validateBean.printQtyChange}"来获取编号

我尝试了onchange="submit()"但是在提交一串打印作业时遇到了问题。 我必须按“ ENTER”来强制激活onchange属性,这已确保用户不需要。


<ice:panelConfirmation>工作方式是暂停表单的提交,并等待响应,然后继续或停止提交。 这完成了我试图通过模式弹出窗口实现的目标。


打印数量输入文本:

<h:inputText id="printQty" value="#{validateBean.printAmount}" size="8" autocomplete="off" 
    maxlength="3" required="true" onblur="submit()" 
    valueChangeListener="#{validateBean.printQtyChange}" />

valueChangeListener:

public void printQtyChange(ValueChangeEvent e) {
    printAmount = e.getNewValue().toString();

    try {
        ls.setPrintQty(Integer.parseInt(printAmount));
    } catch (NumberFormatException eve) {
        errorMessage = true;
        quantityInvalid = true;
        errorFlag = true;
    }

    printQty = ls.getPrintQty();

    System.out.println("Qty : " +printQty);

    if (printQty < 1) {
        errorMessage = true;
        quantityInvalid = true;
        errorFlag = true;
    }
}

面板确认: <ice:form> 在表格关闭之前

<ice:panelConfirmation id="confirmQty"
    acceptLabel="Yes"
    cancelLabel="No"
    message="Your entered the quantity: #{validateBean.printQty}. Is this correct?"
    title="Confirm Quantity"
    draggable="false"
    rendered="#{validateBean.printQty > 2}" />

打印按钮:<ice:panelConfirmation>

<ice:commandButton styleClass="button" id="printButton" value="Print" 
    actionListener="#{validateBean.validate}" panelConfirmation="confirmQty" />

如果有人知道从条件ICEfaces模态弹出窗口调用托管Bean的方法,那也很好。


更新之后,我将所有<h:inputText>更改为<ice:inputText>并在我的输入字段中添加了数量的partialsubmit="true" 通过添加,我已经能够删除onblur="submit()"

新打印数量输入文本:

<ice:inputText id="printQty" value="#{validateBean.printAmount}" size="8" autocomplete="off"
    maxlength="3" required="true" valueChangeListener="#{validateBean.printQtyChange}"
    partialSubmit="true" />

这消除了提交一连串作业时有时仍然存在问题的问题。

我没有在<ice:form>上放置partialsubmit="true" ,因为然后必须将其他所有输入字段声明为partialsubmit="false"以防止执行不必要的代码。 只在我要检查的输入字段上显示它比较整齐。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM