【发布时间】:2017-03-30 13:40:42
【问题描述】:
我有这样的要求。
有一个带有复选框和保存、取消按钮的文件上传器 alopng。
如果文件无效并且选择应该保留,我必须禁用该复选框。
禁用后,如果我单击保存按钮,复选框值在支持 bean 中显示为 false,尽管它在对话框中显示为选中。
在调试时我看到 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>
在调试时我发现在
public void decode(FacesContext context, UIComponent component)
方法
SelectBooleanCheckboxRenderer.java class
该语句中已禁用复选框的 ID 为空。我不明白为什么?如果复选框未被禁用,我将获得正确的值。
String submittedValue = (String) context.getExternalContext().getRequestParameterMap().get(clientId + "_input");
【问题讨论】:
-
如果我正确理解您的问题,您的复选框处于禁用状态,并且值将变为 false,因为禁用字段未在提交按钮上提交,默认值为 false。
标签: primefaces jsf-2