2016-01-25 29 views
0

我正在使用Eclipse Luna EE,Tomcat v7.0和ICEFaces 3.2如何從ICEfaces模式彈出窗口調用託管bean?

我有一個用於輸入信息的標籤打印表單,例如項目號,項目名稱和標籤類型。用戶然後提交表單。這將信息發送到ZPL字符串中的標籤打印機,然後打印出該物品的正確標籤。這一切都沒有問題。

如果價值很高(100+生產),表格會對打印數量進行檢查。如果打印數量超過某個值(純粹出於測試目的),那麼「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!"); 
    } 
+0

我想我已經想出了一個修復。現在正在測試它。我已經刪除了模式彈出窗口,並向qty輸入字段中引入了「valueChangeListener」。然後我添加了一個面板確認,如果數量高於設定值,則會顯示該確認。 – Thraydor

回答

0

我找到了一個替代方案。

我已經刪除了模態彈出窗口和任何與之鏈接的代碼。

我在表格末尾添加了<ice:panelConfirmation>。只有打印數量高於我設定的數字時纔會顯示。

我通過我的打印數量<h:inputText>使用valueChangeListener="#{validateBean.printQtyChange}"onblur="submit()"

獲得數我試過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模式彈出該也會很棒。


UPDATE 我從此改變了我所有的<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",以防止執行不必要的代碼。只有在我想檢查的輸入字段上纔有它。