在 <t:PanelTabbedPane> 内使用 <t:inputFileUpload> 时,<t:message> 无法正确显示

StackOverflow https://stackoverflow.com/questions/66912

  •  09-06-2019
  •  | 
  •  

在 JSP 页面中,我创建了一个 <h:form enctype="multipart/form-data"> 有一些元素: <t:inputText>, <t:inputDate>, , ETC。另外,我还添加了一些 <t:message for="someElement"> 我想允许用户在表单中上传多个文件(一次一个)(使用 <t:inputFileUpload> )此时我的代码工作正常。


当我尝试将表单放入一个 <t:panelTabbedPane serverSideTabSwitch="false"> (当然,在一个 <t:panelTab> )

我复制了 TabbedPane 示例源代码中显示的结构 战斧的例子, ,通过使用 <f:subview> 标签并将 panelTab 标签放入新的 jsp 页面中(使用 <jsp:include page="somePage.jsp"> 指示)

首先, <t:inputFileUpload> 无法按照 Managed Bean UploadedFile 属性中指定的值加载文件 #{myBean.upFile}

然后, 谷歌搜索线索, , 我知道 <t:panelTabbedPane> 生成一个名为“autoform”的表单,因此我得到了嵌套表单。好的,我修复了创建 <h:form> 出于 <t:panelTabbedPane> 和尤里卡!文件输入又可以了!(自动表单不生成)

但是,哦,惊喜!哦,可怕的墨菲定律!我所有的 <h:message> 开始失败。Eclipse 控制台的输出显示所有 <t:message> 正在寻找不存在的元素 ID(其 ID 部分等于他们正在寻找的元素,但在 ID 的末尾,他们的名称发生了变化)

此时,我放置了一个 <t:mesagges> 标签(注意末尾的“s”)在面板的开头立即显示所有验证错误,并且效果很好。因此,存在验证错误,并且它们正确显示在面板的开头。

该页面中生成的所有验证错误消息都是 JSF 内置验证消息。此时的支持 bean 没有定义任何验证器。

¿我怎样才能得到 <t:message for="xyz"> 好好工作?


我在 eclipse Ganymede 项目中使用 Tomahawk-1.1.6 和 myFaces-impl-1.2.3,并使用 Geronimo 作为应用程序服务器(Geronimo 为我提供了 myFaces jar 实现,而我将 tomahawk jar 放在 的 WEB-INF/lib 文件夹中)应用)


“解决了”:此问题是向 myFaces 论坛报告的问题。

感谢 Kyle Renfro 的快速回复和信息。(凯尔干得好!)查看问题


编辑1

1.- 感谢 Kyle Renfro 的快速回复。输入元素内部使用的forceID属性第一次不起作用,但是做一些非常棘手的调整我可以使 <t:message for="xyz"> 标签有效。

我所做的是:
1.有我的标签 <inputText id="name" forceId="true" required="true"><t:message> 不起作用。
2.然后,在查看 Eclipse 控制台上的错误消息后,我将“id”属性重命名为:<输入文本ID =“名称j_id_1“forceId =“true”必需=“true”>
3.然后 <t:message> 工作了!!但第二次按下表单的“提交”按钮后。¡第二次!(我怀疑 JSF 生命周期中发生了一些事情)
4.这意味着用户必须按两次提交按钮才能获取页面上的错误消息。
5.在 ID 末尾使用“j_id_1”短语非常奇怪。


编辑2

好了,代码就到这里了,希望不会让人厌烦。

1.- 主页.jsp (这里是 <t:panelTabbedPane><f:subview> 标签)

<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>  
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>  
<%@ taglib prefix="t" uri="http://myfaces.apache.org/tomahawk"%>  
<html>  
<body>  
<f:view>  
<h:form enctype="multipart/form-data">  
<t:panelTabbedPane serverSideTabSwitch="false" >  

            <f:subview id="subview_tab_detail">  
                <jsp:include page="detail.jsp"/>  
            </f:subview>  

        </t:panelTabbedPane>  
    </h:form>  

</f:view>  
</body>  
</html>  


2.- 详细信息.jsp (这里是 <t:panelTab> 标签)

<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>  
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>  
<%@ taglib prefix="t" uri="http://myfaces.apache.org/tomahawk"%>  

<t:panelTab label="TAB_1">  
        <t:panelGrid columns="3">  
            <f:facet name="header">  
                <h:outputText value="CREATING A TICKET" />  
            </f:facet>  

            <t:outputLabel for="ticket_id" value="TICKET ID" />  
            <t:inputText id="ticket_id" value="#{myBean.ticketId}" required="true" />  
            <t:message for="ticket_id" />  

            <t:outputLabel for="description" value="DESCRIPTION" />  
            <t:inputText id="description" value="#{myBean.ticketDescription}" required="true" />
            <t:message for="description" />  

            <t:outputLabel for="attachment" value="ATTACHMENTS" />  
            <t:panelGroup>  
                <!-- This is for listing multiple file uploads -->  
                <!-- The panelGrid binding make attachment list grow as the user inputs several files (one at a time) -->  
                <t:panelGrid columns="3" binding="#{myBean.panelUpload}" />  
                <t:inputFileUpload id="attachment"  value="#{myBean.upFile}" storage="file" />  
                <t:commandButton value="ADD FILE" action="#{myBean.upload}" />  
            </t:panelGroup>  
            <t:message for="attachment" />  

            <t:commandButton action="#{myBean.create}" value="CREATE TICKET" />  
        </t:panelGrid>  
</t:panelTab>  

编辑3

关于凯尔·伦弗洛 (Kyle Renfro) 后续行动的回应:

凯尔 说:

“在第一次查看页面时,如果您按下“创建票据”按钮,而任何输入文本中都没有任何内容,也没有上传文件,那么消息标签是否适用于输入文本?(IE。required = true)我只是好奇 inputTexts 的消息是否有效,但 inputFileUpload 的消息是否有效。”

这是发现的行为:
1.- 根本没有显示验证错误消息(消息标签不起作用)即使当我尝试仅测试一条验证错误消息(例如,测试第一个输入文本的消息)时,也没有显示任何消息。
2.- Eclipse 控制台向我显示这些内部错误:

ERROR [HtmlMessageRendererBase] Could not render Message. Unable to find component 'ticket_id' (calling findComponent on component 'j_id_jsp_1383779881_1:subview_tab_detail:j_id_jsp_1716158401_0j_id_1:j_id_jsp_1716158401_5j_id_1'). If the provided id was correct, wrap the message and its component into an h:panelGroup or h:panelGrid.  
ERROR [HtmlMessageRendererBase] Could not render Message. Unable to find component 'description' (calling findComponent on component 'j_id_jsp_1383779881_1:subview_tab_detail:j_id_jsp_1716158401_0j_id_1:j_id_jsp_1716158401_8j_id_1'). If the provided id was correct, wrap the message and its component into an h:panelGroup or h:panelGrid.  
ERROR [HtmlMessageRendererBase] Could not render Message. Unable to find component 'attachment' (calling findComponent on component 'j_id_jsp_1383779881_1:subview_tab_detail:j_id_jsp_1716158401_0j_id_1:j_id_jsp_1716158401_14j_id_1'). If the provided id was correct, wrap the message and its component into an h:panelGroup or h:panelGrid.  

这是当我看到 "j_id_1" 生成的 ID 中的单词,例如,对于 id“ticket_id”:

j_id_jsp_1383779881_1:subview_tab_detail:j_id_jsp_1716158401_0j_id_1:j_id_jsp_1716158401_5j_id_1

并且,查看生成的 HTML 页面,我发现 ID 名称如下(不使用“ForceId”属性):

<input id="j_id_jsp_1383779881_1:subview_tab_detail:j_id_jsp_1716158401_0j_id_1:ticket_idj_id_1" name="j_id_jsp_1383779881_1:subview_tab_detail:j_id_jsp_1716158401_0j_id_1:ticket_idj_id_1">  

有帮助吗?

解决方案

看来这可能与我脸上的一个错误有关。您可以尝试一下 myfaces 和 tomahawk 的更新版本。我将删除子视图功能作为快速测试 - 将detail.jsp 页面复制回主页。

https://issues.apache.org/jira/browse/MYFACES-1807?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12567158#action_12567158

其他提示

强制ID 战斧组件的属性应该可以解决这个问题。

就像是:

&lt;t:outputText id="xyz" forceId="true" value="#{mybean.stuff}"/&gt;

在页面的第一个视图中,如果您按下“CREATE TICKET”按钮,而任何 inputTexts 中都没有任何内容,也没有上传文件,那么消息标签是否适用于 inputTexts?(IE。required = true)我只是好奇 inputTexts 的消息是否有效,但 inputFileUpload 的消息是否有效。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top