如果在primefaces中禁用复选框值,则复选框值为false

如果在primefaces中禁用复选框值,则复选框值为false,primefaces,jsf-2,Primefaces,Jsf 2,我有这样的要求 有一个带有复选框和保存、取消按钮的文件上传器 如果文件无效,我必须禁用该复选框,并且选择应该保留 禁用后,如果单击“保存”按钮,则复选框值在backingbean中显示为false,尽管它在对话框中显示为checked 调试时,我看到primeface框架没有获取禁用复选框的id 这是我的xhtml文件: <h:form id="fileupload_form" enctype="multipart/form-data"> <h:panelGro

我有这样的要求

有一个带有复选框和保存、取消按钮的文件上传器

如果文件无效,我必须禁用该复选框,并且选择应该保留

禁用后,如果单击“保存”按钮,则复选框值在backingbean中显示为false,尽管它在对话框中显示为checked

调试时,我看到primeface框架没有获取禁用复选框的id

这是我的xhtml文件:

    <h:form id="fileupload_form" enctype="multipart/form-data">
    <h:panelGroup id="fileupload_Panel">
    <p:message for="fileupload_Panel"></p:message>

    <p:panelGrid styleClass="noBorderGrid global_docs" columns="4">

        <h:outputText style="min-width:100px!important; margin-left: 42px;"></h:outputText>
        <p:selectBooleanCheckbox id="tt" value="#{bean.selectedDocs}"/>
        <h:outputText value="xx}"/>


        <h:outputText style="min-width:100px!important; margin-left: 42px;" rendered="#{cc.attrs.bean != null and cc.attrs.bean.currentDocument != null}"></h:outputText>
        <p:selectBooleanCheckbox id="checkBox" value="#{fileBean.tqpReport}"  disabled="${not fileBean.isActive}"/>
        <h:outputText value="xxxx"/>
        <p:tooltip for="t" value="xxxx"/>

    </p:panelGrid>

    <p:fileUpload id="documentFileUploader" fileUploadListener="#{bean.uploadDocumentsListener}" 
                    mode="advanced" dragDropSupport="true" multiple="true" auto="true"  update="@form" process="@form"
                    onstart="PF('ajax').show();"  onerror="PF('ajax').hide();"
                    style="width: 98%; max-width: 480px; max-height: 150px; overflow: auto;" styleClass="file-uploader-drag-drop" label="#{msgs.choose}" />
    </h:panelGroup>


     <p:panelGrid styleClass="noBorderGrid buttonTable" columns="3" style="float:right;">
         <p:commandButton id="save" icon="ui-icon-disk" styleClass="blue_button" value="${msgs.save}" style="float:right;"
        process="@form" update="@form" action="#{bean.save()}"/>
         <p:commandButton id="cancel" icon="ui-icon-close" styleClass="blue_button" value="${msgs.cancel}"
        action="#{bean.cancel()}"  style="float:right;"
        process="@this"/>
</p:panelGrid> 

 </h:form>
方法

   SelectBooleanCheckboxRenderer.java class 
该语句中禁用复选框的id为空。我不明白为什么?如果该复选框未被禁用,我将获得正确的值

  String submittedValue = (String) context.getExternalContext().getRequestParameterMap().get(clientId + "_input"); 

禁用的元素不会作为零件表单提交发布;你可以看到更多细节。假设您使用的是ViewScope bean,那么当值发生变化时,可以使用AJAX将值发回bean

我尝试了隐藏变量技巧,它对我有效

xhtm文件中隐藏的变量,以及支持bean中的getter和setter

<h:inputHidden id="checkBoxSelection" value="#{fileBean.checkBoxSelection}"/>
因此,在保存时,复选框值将设置为backingbean


如果我正确理解了您的问题,您的复选框处于禁用状态,值为false,因为禁用字段未在提交按钮上提交,默认值为false。
<h:inputHidden id="checkBoxSelection" value="#{fileBean.checkBoxSelection}"/>
 <p:commandButton id="save" icon="ui-icon-disk" styleClass="blue_button" value="${msgs.save}" style="float:right;"
    process="@form" update="@form" action="#{fileBean.saveUploadedDocuments(cc.attrs.id)}" 
 onclick="sendCheckBoxSelection('fileupload_form_widget_tqpReportCheckBox','fileupload_form:checkBoxSelection');"/>
function sendCheckBoxSelection(checkBoxId,hiddenparamId){
var checkBoxSelection = false;
var tqpCheckBox = getWidgetVarById(checkBoxId);
if (tqpCheckBox != null){
    checkBoxSelection = PrimeFaces.widgets[checkBoxId].input.is(':checked')
    document.getElementById(hiddenparamId).value = checkBoxSelection;
  }
}

 function getWidgetVarById(id) {
for (var propertyName in PrimeFaces.widgets) {
  if (propertyName === id) {
    return PrimeFaces.widgets[propertyName];
   }
  }
}