简体   繁体   English

SelectBooleanCheckbox无需鼠标悬停即可获得焦点

[英]SelectBooleanCheckbox receives focus without mouseover

I have a weird problem with jsf components (h:inputFile & h:selectBooleanCheckbox). 我对jsf组件有一个奇怪的问题(h:inputFile和h:selectBooleanCheckbox)。

Both components receive focus, even when my mouse is somewhere else on the page. 即使我的鼠标在页面上的其他位置,这两个组件也都获得焦点。 Here is the code: 这是代码:

<h:form id="logoUpload" enctype="multipart/form-data">
  <div>      
   <h:outputLabel rendered="true">
      <h:inputFile id="companyLogo" label="file" value="#{fileHandlerBean.part}" >
       <f:validator validatorId="FileUploadValidator" />
      </h:inputFile>
   </h:outputLabel>
 </div>

<div class="clear" />

<h:outputLabel rendered="true">
 <div>
   <div style="width: 5%">
    <h:selectBooleanCheckbox id="acceptToULogo" value="#{companyEditController.confirmToU}">
     <p:ajax event="change" update="buttonLogo" />
    </h:selectBooleanCheckbox>
 </div>

  <div style="width: 95%">
  <h:outputText value="Some Text " /> 
  </div>
 <br />

<h:commandButton id="buttonLogo" styleClass="formbutton" value="Upload"
      action="#{companyEditController.companyLogoUpload()}" 
      actionListener="#{fileHandlerBean.uploadCompanyLogo()}" 
      disabled="#{!companyEditController.confirmToU}"/>    
 </div>
</h:outputLabel>
</h:form>

If I move the mouse over the h:outputText the checkbox receives focus. 如果将鼠标移到h:outputText上方,则复选框将获得焦点。 I had the same problem with the h:inputFile tag. 我在h:inputFile标记上遇到了同样的问题。 I solved it by surrounding it with ah:outputLabel tag, but unfortunately it doesn´t workd with the selectBooleanCheckbox. 我通过用ah:outputLabel标记将其包围来解决它,但是不幸的是,它不能与selectBooleanCheckbox一起使用。

Did somebody have the same problem in the past and knows a solution? 过去有人遇到过同样的问题并且知道解决方案吗?

This is because everything is wrapped in the h:outputLabel tag. 这是因为所有内容都包装在h:outputLabel标记中。 This outputLable is rendered as a plain label html element. 此outputLable呈现为纯标签html元素。

You can see form the W3C specification that anything inside the label will toggle the control 您可以从W3C规范中看到,标签内的任何内容都会触发控件

The element does not render as anything special for the user. 元素不会呈现为用户的任何特殊内容。 However, it provides a usability improvement for mouse users, because if the user clicks on the text within the element, it toggles the control 但是,它为鼠标用户提供了可用性改进,因为如果用户单击元素内的文本,则会切换控件。

To fix this, you need to replace the h:output label tag using ah:panelGroup layout="block" which renders a <div> : 要解决此问题,您需要使用ah:panelGroup layout =“ block”替换h:output标签标记,这会呈现<div>

<h:panelGroup layout="block" rendered="true">
 <div>
   <div style="width: 5%">
    <h:selectBooleanCheckbox id="acceptToULogo" >
     <p:ajax event="change" update="buttonLogo" />
    </h:selectBooleanCheckbox>
 </div>

  <div style="width: 95%">
  <h:outputText value="Some Text " /> 
  </div>
 <br />

<h:commandButton id="buttonLogo" styleClass="formbutton" value="Upload"/>    
 </div>
</h:panelGroup>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM