【问题标题】:Why are these PrimeFaces radio buttons disabled?为什么禁用这些 PrimeFaces 单选按钮?
【发布时间】:2013-06-11 16:55:58
【问题描述】:

我有一些我认为很简单的代码:

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

即使这样也不能完全发挥作用;选择一个单选按钮并转到下一页正确绑定。但是,当我返回一个页面时,单选按钮再次被禁用!

【问题讨论】:

  • 您是否尝试将第一组 selectOneRadio 从 h:selectOneRadio 更改为 p:selectOneRadio?如果这只是一个错字,请提供完整的 xhtml
  • 是的,原来是 p:selectOneRadio; h:是我绝望地尝试过的东西!我已经添加了完整的代码。
  • 对不起 - 我浪费了你的时间。当我将代码复制为简洁的编辑格式时,我意识到加载时会触发一些我以前没有注意到的 javascript,删除它解决了问题!感谢您的帮助。

标签: java jsf-2 primefaces spring-webflow


【解决方案1】:

以防万一它对其他人有用,我的单选按钮被禁用的原因是由于看似不相关的代码部分引发了 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-19
    • 1970-01-01
    相关资源
    最近更新 更多