在Java Web中同时创建对象的问题

时间:2016-12-20 04:45:14

标签: maven jsf primefaces jboss

我使用spring primefaces开发了maven web项目并在jboss 5.0服务器上运行 应用程序基于云,多个用户可以同时访问 我的问题是什么时候创建对象有时会引用前一个对象。这可以顺序完成。但是,当并行调用相同的方法时,它会以模糊的方式运行。这是问题的主要问题吗?

depositController method:
@ManagedBean(name = "depositController")
@ViewScoped
public class DepositController {
public void depositAcc(ActionEvent actionEvent) {

    try {            
        validate = true;
        TrxnObj tempTrxnObj = trxnObj;
        if (requiredFieldValidate()) {
            this.mobileNoVerify();
            if (validate) {
                this.amountValidate();
            }
        } else {
            FacesContext context = FacesContext.getCurrentInstance();
            FacesMessage message = new FacesMessage();
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            message.setSummary("Please Enter the Required Fields");
            context.addMessage("ad", message);
            return;
        }
        if (!validate) {
            return;
        }

        if (isRCP) {
            if (null == userManager) {
                userManager = (UserManager) SpringUtil.getApplicationContext().getBean("userManager");
            }                
            merchant = userManager.getMerchantDetails(AppConstants.TRXN_CODE_WALLET_CASH_IN_WEB, merchantID);

            if (null == commonManager) {
                commonManager = (CommonManager) SpringUtil.getApplicationContext().getBean("commonManager");
            }
            //insert txn id
            WSRequest request = new WSRequest();
            request.setMerchantId(merchantID);
            request.setMerchantOutletCode(merchantOutletCode);
            request.setCustomerMobileNumber(tempTrxnObj.getMobileNo());
            request.setMobileNumber(merchant.getMobileNumber());
            request.setPinCode(merchant.getPinCode());
            request.setTransactionAmount(tempTrxnObj.getAmount().doubleValue());
            if(branchCode!=null && !branchCode.equals("")){
                request.setUserName(userId+"-"+branchCode);
            }else{
                request.setUserName(userId);
            }
            if (tempTrxnObj.getNote() == null || tempTrxnObj.getNote().isEmpty()) {
                request.setNote("Cash In at " + merchantID + " for " + tempTrxnObj.getMobileNo());
            } else {
                request.setNote(tempTrxnObj.getNote());
            }
            request.setMerchantTransactionId(getRCPTransactionRef());

            CashInRequest cashInRequest = new CashInRequest();
            cashInRequest.setWsRequest(request);
            CashInResponse cashInResponse = commonManager.callCashInService(cashInRequest);

            if (cashInResponse.getWsResponse().getResponseCode() == AppConstants.WS_TRXN_WEB_RES_SUCCESS) {
                FacesContext.getCurrentInstance().addMessage("ad", new FacesMessage("Transaction Success: " + cashInResponse.getWsResponse().getResponse()));
                receiptObj.setValues(this.trxnObj, locationShortCode, customerName);
                recieptPrintEnabled = true;
                receiptObj.setRefNumber(cashInResponse.getWsResponse().getReference());
                receiptObj.setCusName(userControlObj.getMwtUserWalletDetails().getName());
                receiptObj.setUtilityType("CASH IN");
                receiptObj.setAccountNumber(userControlObj.getMwtUserWallet().getMobileNo());
                receiptObj.setNote("Accepted payment for CASH IN.Thank You.");
                reset();
            } else {

                FacesContext context = FacesContext.getCurrentInstance();
                FacesMessage message = new FacesMessage();
                message.setSeverity(FacesMessage.SEVERITY_ERROR);
                message.setSummary("Transaction Failed");
                context.addMessage("ad", message);
            }
        }
    }catch(Exception e){
        log.error(e,e)
    }   
}       

DepositAcc.xhtml:                   

            <p:messages id="msgs" for="ad" globalOnly="true"/>

            <h:panelGrid columns="9" cellpadding="5" id="add_edit" styleClass="add-form">   

                <h:outputLabel for="mobileNo" value="*Confirm Mobile No:"/> 
                <p:inputText id="mobileNo" value="#{depositController.mobileNoCnfrm}" required="true" disabled="#{depositController.trxnObj.mobileNo == null}">
                </p:inputText>
                <p:message for="mobileNo" display="icon"/>

                <h:outputLabel for="amount" value="*Deposit Amount:"/> 
                <p:inputText id="amount" value="#{depositController.trxnObj.amount}" onkeyup="$(this).val(addCommas($(this).val()))" required="true" disabled="#{depositController.trxnObj.mobileNo == null}">                                                   
                    <f:convertNumber maxFractionDigits="2"
                                     groupingUsed="true"                                                                                
                                     pattern="#,##0.00"/>
                </p:inputText>
                <p:message for="amount" display="icon"/> 

                <h:outputLabel for="amountCnfrm" value="*Confirm Amount:"/> 
                <p:inputText id="amountCnfrm" value="#{depositController.amountCnfrm}" onkeyup="$(this).val(addCommas($(this).val()))" required="true" disabled="#{depositController.trxnObj.mobileNo == null}">                                                   
                    <f:convertNumber maxFractionDigits="2"
                                     groupingUsed="true"                                                                                
                                     pattern="#,##0.00"/>
                </p:inputText>
                <p:message for="amountCnfrm" display="icon"/>      

                <h:outputLabel for="location" value="*Branch Location:" rendered="#{!depositController.isRCP}"/> 
                <p:inputText id="location" value="#{depositController.location}" required="true" disabled="true" style="width: 200px" rendered="#{!depositController.isRCP}">                                                   
                </p:inputText>
                <p:message for="location" display="icon" rendered="#{!depositController.isRCP}"/>                     

                <h:outputLabel for="note" value="Note:"/>
                <p:inputTextarea id="note" value="#{depositController.trxnObj.note}" disabled="#{depositController.trxnObj.mobileNo == null}"
                                 rows="4" cols="20" counter="counter" maxlength="100"       
                                 counterTemplate="({0}/100)">
                </p:inputTextarea>
                <h:outputText id="counter"/>
                <p:message for="note" display="icon"/>

            </h:panelGrid>  


            <h:panelGrid columns="3" cellpadding="5" id="btns" styleClass="add-btn">                    

                <p:commandButton value="Deposit" ajax="true" update=":add:addFields :add:btns :list :dialog" actionListener="#{depositController.depositAcc}" 
                                 disabled="#{!depositController.depositEnable}"/>

                <p:commandButton value="Reset" update="addFields btns" process="@this" 
                                 disabled="#{!depositController.depositEnable}"
                                 actionListener="#{depositController.reset}"/>

                <p:commandButton value="View Receipt" onclick="dlg.show()" 
                                 disabled="#{!depositController.recieptPrintEnabled}"/>

            </h:panelGrid>

        </p:fieldset>

    </h:form>    

0 个答案:

没有答案