为什么禁用这些PrimeFaces单选按钮?

时间:2013-06-10 16:15:58

标签: java jsf-2 primefaces spring-webflow

我认为这是一些简单的代码:

<ui:composition template="/templates/webflow.xhtml"
            xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:p="http://primefaces.org/ui"
            xmlns:f="http://java.sun.com/jsf/core">

<ui:define name="flowTitle">Page One</ui:define>
<ui:define name="pageTitle">Page 1 of 5: Please select a type</ui:define>

<ui:define name="content">
    <h:form id="page1Form">
        <div class="flow_main">
            <div class="controls">
                <p:selectOneRadio id="customRadio" value="#{flowState.selectedOption}" layout="custom">
                    <f:selectItem itemValue="-1" />
                    <f:selectItem itemValue="1" />
                    <f:selectItem itemValue="2" />
                    <f:selectItem itemValue="3" />
                    <f:selectItem itemValue="4" />
                    <f:selectItem itemValue="5" />
                    <f:selectItem itemValue="6" />
                </p:selectOneRadio>

                <!-- these to go into a datatable -->
                <p:radioButton id="opt2" for=":page1Form:customRadio" itemIndex="1"/>
                <p:radioButton id="opt3" for=":page1Form:customRadio" itemIndex="2"/>
                <p:radioButton id="opt4" for=":page1Form:customRadio" itemIndex="3"/>
                <p:radioButton id="opt5" for=":page1Form:customRadio" itemIndex="4"/>
                <p:radioButton id="opt6" for=":page1Form:customRadio" itemIndex="5"/>
                <p:radioButton id="opt1" for=":page1Form:customRadio" itemIndex="6"/>

            </div>
        </div>
        <div style="text-align:right" class="flow_footer" >
            <p:commandButton id="cancel" value="Cancel" ajax="true" action="cancel" onsuccess="javascript:parent.dlg.hide();"/>
            <p:commandButton id="next" action="next" value="Next" onclick="return validate(1)" update="@form" />
        </div>
    </h:form>
</ui:define>

然而,渲染时,3个底部单选按钮被禁用。我已经尝试改变所有属性以使它们启用但无济于事。

我设法启用它们的唯一方法是添加以下行:

<h:inputHidden value="#{flowState.selectedOption}" id="hiddenId" />

尽管如此,这并不完全有效;选择单选按钮并转到下一页正确绑定。但是,当我返回页面时,再次禁用单选按钮!

1 个答案:

答案 0 :(得分:0)

以防它对其他人有用,我的单选按钮被禁用的原因是由于看似无关的代码部分引发了javascript错误:

<ui:define name="content">
    <script>
        jQuery(document).ready(function() {
            var selected = document.getElementById("page1Form:hiddenId").value;
            if(selected != -1) {
                document.getElementById("page1Form:typeTable:" + selected + ":chkType").checked = true;
            }
        });
    </script>