简体   繁体   中英

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

I am using Eclipse Luna EE, Tomcat v7.0 and ICEFaces 3.2

I have a form for label printing that the user enters information such as item number, item name and label type. The user then submits the form. This sends the information to a label printer, in a ZPL string, which then prints out the correct label for the item. This all works no problem.

The form makes a check against the print quantity, in case of a high value (100+ in production). If the print quantity is over a certain value (> 2. purely for testing purposes) then the "testFlag" boolean is set to true, the modal box is displayed and an error flag is set so that the print command doesn't execute.

The modal box asks if the user entered the correct quantity, with Yes/No buttons available.

The printUI and the modal popup are inside the same <ice:form> element, with the popup box rendered and visible if the testFlag is set to true.

The Problem: When I click the "Yes" button in the modal box, it doesn't carry out the action I have assigned to it ( System.out.println("Yes Button!") ). The modal box closes and nothing happens.

I can then resubmit the form and the modal box appears again, then I click "Yes" and nothing happens.

If I change the quantity to 2 and submit, then it executes the print command no problem.

I am guessing that it is a problem with the way the session is being handled.

Question: How do I get the "Yes" button on the modal box to carry out the code I am wanting?

I've tried: Using <ice:commandLink> , <h:button> , <h:commandButton> , <h:commandLink>

Having the modal popup and the form in separate <ice:form> tags (This refreshed the session and removed all entered data).

Using an actionListener

code containing the form:

<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>

Relevant ValidateBean.java code

    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!");
    }

I found an alternative.

I have removed the modal popup and any code linked with it.

I have added in a <ice:panelConfirmation> at the end of my form. This is only rendered if the print quantity is above whatever number I set.

I get the number by using a valueChangeListener="#{validateBean.printQtyChange}" on my Print Quantity <h:inputText> with onblur="submit()"

I tried the onchange="submit()" but ran into problems when submitting a string of print jobs. I would have to press "ENTER" to force the onchange attribute to activate, which I have been assured the users don't want.


The <ice:panelConfirmation> works by pausing the submit of the form and waits for a response before it either continues or stops the submit. Which accomplishes what I was trying to achieve with the modal popup.


Print Quantity Input Text:

<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;
    }
}

Panel Confirmation: inside the <ice:form> . Just before the closing of the 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}" />

Print Button: tied in with the <ice:panelConfirmation>

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

If anyone does know of a way to invoke a managed bean from a conditional ICEfaces modal popup that would be great also.


UPDATE I've since changed all my <h:inputText> to <ice:inputText> and added the partialsubmit="true" to my input field for the quantity. with adding this I have been able to remove the onblur="submit()"

NEW Print Quantity Input Text:

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

This has removed the issue where sometimes it still had problems when submitting a string of jobs.

I haven't put partialsubmit="true" on the <ice:form> because I had to then declare every other input field as partialsubmit="false" to prevent unnecessary code being executed. It's tidier to only have it on the input field I want to check.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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