【问题标题】:Primefaces p:focus not workingPrimefaces p:焦点不起作用
【发布时间】:2015-05-02 08:16:54
【问题描述】:

我需要焦点指定 ID(即命令按钮、选择菜单和文本)不起作用。我试试下面的代码:

<h:form id="mainForm">
<p:inputText id="name"/>
<p:inputText id="Age"/>
   <p:selectOneRadio id="Gender" value="#{employee.gender}" layout="custom">
            <f:selectItem itemLabel="Male" itemValue="Male" />
            <f:selectItem itemLabel="Female" itemValue="Female" />

        </p:selectOneRadio>
<p:commandButton  id="clear" value="Press" action="{employee.saveAction}">
<p:focus for="Gender"/>
</p:commandButton>

<p:commandButton id="clear" value="clear"/>
</h:form>

我尝试焦点单选按钮或 id="clear" 命令按钮或文本按钮没有焦点。

注意:我试过 context="specifyid" 替换它也不起作用。

【问题讨论】:

  • 它适用于“年龄”吗?我想我读到了焦点不适用于选择(虽然不确定,但搜索互联网可能会产生一些东西)

标签: jsf primefaces


【解决方案1】:

我不知道你为什么把&lt;p:focus&gt; 放在&lt;p:commandButton&gt; 里面。也许这会引起问题。根据docs,您可以将标签直接放入&lt;h:form&gt;,并将焦点放在您的&lt;p:selectOneRadio&gt;

<h:form id="mainForm">
  <p:focus for="Gender" />
  <p:inputText id="name" />
  <p:inputText id="Age" />
  <p:selectOneRadio id="Gender" value="#{employee.gender}" layout="custom">
    <f:selectItem itemLabel="Male" itemValue="Male" />
    <f:selectItem itemLabel="Female" itemValue="Female" />
  </p:selectOneRadio>
  <p:commandButton id="clear" value="Press" action="{employee.saveAction}" />
  <p:commandButton id="clear" value="clear" />
</h:form>

【讨论】:

  • 当按下命令按钮焦点时指定 id 因为我使用了多个命令按钮和多个焦点。所以我点击commandbutton来关注指定ID
  • 你为什么不用 JavaScript 来代替呢? onclick="document.getElementById("Gender").focus();"
  • 它聚焦,但它使用页面必须引用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多