3

我正在尝试将 tooptips 附加到 ui:repeat 循环中的 commandButtons。我动态地创建命令按钮的 ID 和工具提示的“for”属性。这会产生以下错误:

    HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Cannot find component "a_test" in view.
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:325)
    org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
root cause

javax.faces.FacesException: Cannot find component "a_test" in view.
    org.primefaces.component.tooltip.TooltipRenderer.getTarget(TooltipRenderer.java:93)
    org.primefaces.component.tooltip.TooltipRenderer.encodeScript(TooltipRenderer.java:66)
    org.primefaces.component.tooltip.TooltipRenderer.encodeEnd(TooltipRenderer.java:35)
    javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:883)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
    com.sun.faces.facelets.component.RepeatRenderer.encodeChildren(RepeatRenderer.java:104)
    com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:504)
    com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:958)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1652)
    javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:853)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1652)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655)
    com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:399)
    com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
    org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.12 logs.

Apache Tomcat/7.0.12

我的jsf如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head></h:head>
<h:form id="MyForm">
    <ui:repeat var="rs"
        value="#{rezervasyonBean.rezervasyonSaatleriListesi}">
        <p:commandButton action="#" value="#{rs.saatAraligi}"
            update="@form" 
            id="#{rs.saatAraligi}_test" 
        />

        <p:tooltip for="#{rs.saatAraligi}_test" value="test text"/>
    </ui:repeat>

</h:form>
</html>

rezervasyonBean.rezervasyonSaatleriListesi 是列表,rs.saatAraligi 的元素是 a、b、c。

我的问题是:如何以相同的方式动态识别 ui 组件和 p:tooltip 的“for”属性?

问候。

4

1 回答 1

7

JSF UI 组件的 ID 属性是在视图构建期间评估的,但是<ui:repeat>在视图渲染期间运行,因此#{rs.saatAraligi}将评估为null,因此命令按钮的 ID 将始终为_test.

只需从and中删除#{rs.saatAraligi}表达式。你在这里不需要它。JSF 会自动为 的迭代索引添加前缀,从而确保 ID 的唯一性。idfor<ui:repeat>

<p:commandButton action="#" value="#{rs.saatAraligi}"
    update="@form" 
    id="test" 
/>
<p:tooltip for="test" value="test text"/>

也可以看看:

于 2012-11-11T00:04:41.507 回答