0

I am using Primefaces3.5 with Jsf2.1.9 i am getting a weired issue with

 <p:commandButton>

as well as

 <p:commandLink>

I have to press button as well as link more than one then JSF bean method is calling otherwise on Single click nothing Happening as i read some Stackoverflow Question this Issue relates to JSF but even using Primfaces3.5 with their Components i am getting this issue.Any one know How can i resolve this issue. My JSF page

<ui:composition xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:p="http://primefaces.org/ui"
    template="./../portfolio/PortfolioViewTemplate.xhtml">


    <ui:define name="moduleContent">

        <p:panel id="panel" header="Portfolio Transaction">
            <p:messages id="msgs" />


            <p:panelGrid id="addMoreTrans" columns="2" style="border-style:none;">
                <f:facet name="header">
                       Add Trades
                </f:facet>
                <p:dataTable var="moreTrans"
                    value="#{portfolioTransactionBean.listOfTrasPanel}" style="border:none;" >

                    <p:column style="border:none;">
                        <p:panelGrid columns="7" id="transactionPanel1"
                            style="display: inline-block;border:none;">


                            <h:outputLabel for="tipsSuggestionBoxId" value="Company Name:*"></h:outputLabel>

                            <h:outputText value="Date:*" />

                            <h:outputText value="Type:*" />

                            <h:outputText value="Quantity:*" />

                            <h:outputText value="Price:*" />

                            <h:outputText value="Brokerage:" />

                            <h:outputText value="Notes:" />

                            <p:autoComplete id="tipsSuggestionBoxId"
                                completeMethod="#{applicationScopeBean.autoSelectCompany}"
                                value="#{portfolioTransactionBean.txnCurrentRecord.companyName}"
                                minChars="3" nothingLabel="No similar company found"
                                requestDelay="1" minQueryLength="3" required="true"
                                requiredMessage="Company Name Cannot be empty">
                            </p:autoComplete>

                            <p:calendar id="from_date1" size="10" required="true"
                                requiredMessage="Date Cannot be empty"
                                value="#{portfolioTransactionBean.txnCurrentRecord.umptTransDate}"
                                mode="popup" showOn="both" pattern="dd/MM/yyyy"
                                popupIconOnly="true" readonly="#{facesContext.renderResponse}"
                                navigator="true" showButtonPanel="true">
                            </p:calendar>

                            <p:selectOneMenu id="tranType"
                                value="#{portfolioTransactionBean.txnCurrentRecord.umptTransType}">
                                <f:selectItem itemLabel="Transaction Type" itemValue="" />
                                <f:selectItem itemLabel="Buy" itemValue="Buy" />
                                <f:selectItem itemLabel="Sell" itemValue="Sell" />
                                <f:selectItem itemLabel="Bonus" itemValue="Bonus" />
                                <f:selectItem itemLabel="Split" itemValue="Split" />
                            </p:selectOneMenu>


                            <p:spinner id="transQuntity1" required="true"
                                value="#{portfolioTransactionBean.txnCurrentRecord.umptQty}"
                                min="1" label="Quanity" size="5"
                                validatorMessage="Field Is mandatory" />

                            <p:spinner id="transPrice1" required="true" size="5"
                                value="#{portfolioTransactionBean.txnCurrentRecord.umptPrice}"
                                label="Price" validatorMessage="Field Is mandatory" />



                            <p:spinner id="brokerage1" size="5"
                                value="#{portfolioTransactionBean.txnCurrentRecord.umptBrokerage}" />

                            <h:inputText
                                value="#{portfolioTransactionBean.txnCurrentRecord.umptNotes}" />

                        </p:panelGrid>
                    <p:separator id="customSeparator" style="width:100%;height:10px" />

                    </p:column>
                </p:dataTable>
                <f:facet name="footer">


                    <p:commandButton value="Clear"
                        actionListener="#{portfolioTransactionBean.clearRecord}"
                        process="@this"
                        rendered="#{portfolioTransactionBean.onClickofButton}">
                    </p:commandButton>
                    <p:spacer width="100" height="10" />
                    <p:commandButton value="Save Transaction " icon="ui-icon-check"
                        action="#{portfolioTransactionBean.savePortfolioTransaction}"
                        style="float:right;right:20%;"
                        rendered="#{portfolioTransactionBean.onClickofButton}">

                    </p:commandButton>
                    <p:commandButton value="Add More Transaction " icon="ui-icon-check"
                        action="#{portfolioTransactionBean.addMoreTransPanel}"
                        process="@this" update="addMoreTrans"
                        rendered="#{portfolioTransactionBean.onClickofButton}" />


                </f:facet>
            </p:panelGrid>



            <p:panelGrid columns="2" id="allTransactionPanel">
                <p:dataTable value="#{portfolioTransactionBean.transactionsList}"
                    var="tradeRec">
                    <f:facet name="Header">
                        <h:outputText>Recently Added Trades</h:outputText>
                    </f:facet>

                    <p:column headerText="Company">
                        <h:outputText value="#{tradeRec.companyName}"></h:outputText>
                    </p:column>
                    <p:column headerText="Date">
                        <h:outputText value="#{tradeRec.umptTransDate}">
                            <f:convertDateTime dateStyle="medium"></f:convertDateTime>
                        </h:outputText>
                    </p:column>
                    <p:column headerText="Type">
                        <h:outputText value="#{tradeRec.umptTransType}"></h:outputText>
                    </p:column>
                    <p:column headerText="Quantity">
                        <h:outputText value="#{tradeRec.umptQty}"></h:outputText>
                    </p:column>
                    <p:column headerText="Price">
                        <h:outputText value="#{tradeRec.umptPrice}">
                            <f:convertNumber maxFractionDigits="2"></f:convertNumber>
                        </h:outputText>
                    </p:column>
                    <p:column headerText="Brokerage">
                        <h:outputText value="#{tradeRec.umptBrokerage}">
                            <f:convertNumber maxFractionDigits="2"></f:convertNumber>
                        </h:outputText>
                    </p:column>
                </p:dataTable>
            </p:panelGrid>
        </p:panel>

    </ui:define>
</ui:composition>

Template File...

<ui:composition xmlns:jsp="http://java.sun.com/JSP/Page" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:p="http://primefaces.org/ui" 
    template="./../templates/MasterTemplate.xhtml">


    <ui:define name="moduleDetails">
        <h:form name="portfolioMenuForm">
        <f:event type="javax.faces.event.PreRenderViewEvent" listener="#{applicationScopeBean.preRenderView}"/>
            <table style="width: 100%; min-height: 500px; border: none">

                <tr>
                    <td>
                    <p:menu>
                        <p:submenu label="Portfolio Views"> 
                            <p:menuitem value="Add Transactions" action="PortfolioTransactionMgmt" update="@form"   immediate="true" />
                            <p:menuitem value="View Transactions"  action="PortFolioTranView"   update="@form"   immediate="true"  />
                            <p:menuitem value="Latest Holdings"  action="PortfolioHolding"  update="@form" immediate="true" />
                            <p:menuitem value="Sector Allocations"  action="#{portfolioTransactionBean.showSecAllocation}"  update="@form" immediate="true" />
                            <p:menuitem value="Realized Profit"  action="PortfolioRelizeProfit"  update="@form" immediate="true" />
                            <p:menuitem value="Portfolio Performance"  action="#{portfolioTransactionBean.showPortPerformance}"  update="@form" immediate="true" />
                            <p:menuitem value="Benchmark Comparison"  action="#{portfolioTransactionBean.showBenhComparison}"  update="@form" immediate="true" />
                         </p:submenu>   
                    </p:menu>
                    </td>
                    <td>
                        <ui:insert name="moduleContent"></ui:insert>
                    </td>
                </tr>

            </table>
        </h:form>
    </ui:define>


</ui:composition>
Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
  • Put this components in context of your problem, and show us your code. – partlov Feb 17 '13 at 16:24
  • OK, can you put some main things from template. I don't se `h:form` here. Also is this in some dialog? Did you try JavaScript and NET debugging with Firebug on first click? – partlov Feb 17 '13 at 16:49
  • Added template file . i am not using any dialog – Subodh Joshi Feb 17 '13 at 17:13
  • You don't have any more forms in MasterTemplate.xhtml? Possible nested forms? Also, why don't you updating anything on first and second command buttons? – partlov Feb 17 '13 at 17:20
  • I have one more Nested template... and update="addMoreTrans" is for updating datalist so it will add one more element in list – Subodh Joshi Feb 17 '13 at 17:25
  • I see you main `xhtml` page is not inside ``.May be this helps you.http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked – SRy Feb 18 '13 at 05:12
  • I have form inside template – Subodh Joshi Feb 18 '13 at 05:13
  • Post an SSCCE, please. There's too much code noise here and you aren't clearly showing/describing the path to the problem. – BalusC Feb 18 '13 at 12:03
  • @BalusC i added code becuase some other developer want to see the code..And my issue is i have to double click on button and link to process a request? – Subodh Joshi Feb 18 '13 at 12:24
  • You should post code in SSCCE flavor and not blindly copypaste code dumps. An SSCCE is the **smallest possible but complete, compilable and executable** code snippet which anyone (including yourself!) should be able to copy'n'paste'n'run into a completely blank environment with everything set to default (unless explicitly otherwise specified) in order to successfully reproduce the concrete problem. – BalusC Feb 18 '13 at 12:40

2 Answers2

0

Basically this is not weired issue On first click jsf first looks whether there is (javax.faces.ViewState) state available or not and if it is not available then it creates one for you & when you click second time because of Jsf state available it makes call to bean method. Solution : try creating jsf state through the javascript function

psi
  • 269
  • 2
  • 13
  • I dont want to Use JS in My Application ... And check http://stackoverflow.com/questions/10814888/have-to-press-command-button-twice its a Issue and Fixed in JSF2.2 but i dont know If Primefaces3.5 Support JSF2.2 – Subodh Joshi Feb 17 '13 at 16:40
0

Thanks to Çağatay Çivici Project lead of primefaces .He suggest me

Try with 2.1.17 then, showcase is 2.1.17.

So i updated my pom for jsf and it work like a charm.

Thanks

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202