动态按钮操作在jsf中不起作用

时间:2014-11-20 09:08:14

标签: java jsf web

在JSF中。 我正在使用“选择”标记。启动时== true,panelGrid将显示。否则启动CommandButton将显示。 所以当我点击Start CommandButton时,我设置了start = true;和更新表格。

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

该网格还包括CommandButton。它被命名为Finish。

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

当我单击Finish CommandButton时,不调用ShowResult()方法。 为什么不打电话?我不知道。

此外,我尝试不使用“选择”标记。它工作正常。

public void showResult() {

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

        }

2 个答案:

答案 0 :(得分:0)

一般情况下,不要混用JSF(h:和f :)标签和JSTL(c :)标签。这会产生意想不到的结果,因为它们被评估为JSF生命周期中的不同点。

我解决这个问题的方法是使用rendered属性。它也更整洁:

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

答案 1 :(得分:0)

解决了。我添加了RealSam managedBean的@SessionScoped头。谢谢大家的建议

相关问题