简体   繁体   中英

Dynamic button action not working in jsf

In JSF. I am using a " choose " tag. When started ==true panelGrid will show. else Start CommandButton will show. So when I click on Start CommandButton I set started =true; and UPDATE form.

<h:form id="frmBig">
                        <c:choose>
                            <c:when test="#{realExam.started}">
                                <p:panelGrid id="pnlExam" binding="#{realExam.grid}"/>
                            </c:when>
                            <c:otherwise>
                                <p:commandButton value="Start" binding="#{realExam.cmdBtn}"/>
                            </c:otherwise>
                        </c:choose>
                    </h:form>

That grid include also CommandButton. It is named Finish.

button.setId("btnFin");
        button.setValue("Finish");
        button.setActionExpression(createMethodExpression("#{realExam.showResult}", null));

When I click Finish CommandButton, not calling ShowResult() method. Why it is not calling? I do not know.

Also I tried not using " choose " tag. it is working fine.

public void showResult() {

    System.out.println("fin clicked");

        }

In general, don't mix JSF (h: and f:) tags and JSTL (c:) tags. This can produce unexpected results as they are evaluated a different points in the JSF lifecycle.

The way I would solve this is to use the rendered attribute. It's also much neater:

<h:form id="frmBig">
    <p:panelGrid id="pnlExam" binding="#{realExam.grid}" rendered="#{realExam.started}"/>
    <p:commandButton value="Start" binding="#{realExam.cmdBtn}" rendered="#{not realExam.started}"/>
</h:form>

It Solved. I added @SessionScoped head of RealExam managedBean. thanks for your all suggests

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