内部使用时无法正确显示

时间:2020-03-05 18:54:31  来源:igfitidea点击:

在JSP页面中,我创建了一个<h:form enctype =" multipart / form-data">,其中包含一些元素:&lt;t:inputText>,&lt;t:inputDate>等。此外,我还添加了一些<t:message for =" someElement">,并且我想允许用户在表单中(使用<t:inputFileUpload>`一次上传几个文件)(一次)。

当我尝试将表单放入&lt;t:panelTabbedPane serverSideTabSwitch =" false">(当然也就是&lt;t:panelTab>)中时,头痛就来了

我通过使用&lt;f:subview>标记并将panelTab标记放入新的jsp页面(使用&lt;jsp:include page =" somePage.jsp")中,从Tomahawk的示例中复制了TabbedPane示例的源代码中所示的结构。 ">指令)

首先,<t:inputFileUpload>无法以受管Bean UploadedFile属性## myBean.upFile}中指定的值加载文件。

然后,搜寻一个线索,我知道&lt;t:panelTabbedPane>会生成一个称为" autoform"的表单,因此我正在嵌套表单。好的,我修复了从<t:panelTabbedPane>和eureka中创建&lt;h:form>的问题!文件输入再次起作用! (自动表单不会生成)

但是,哦,惊喜!哦,墨菲法则太糟糕了!我所有的<h:message>都开始失败。 Eclipse控制台的输出显示所有&lt;t:message>都在寻找不存在的元素ID(其ID部分等于他们在寻找的ID,但在ID末尾其名称会更改)

在这一点上,我放置了一个<t:mesagges>标签(在末尾注明" s"),以便在面板开始时立即向我展示所有验证错误,并且工作正常。因此,存在验证错误,并且这些错误会正确显示在面板的开头。

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

怎样才能使<< t:message for =" xyz">`正常工作?

我在带有Geronimo作为应用服务器的Eclipse Ganymede项目中使用带有myFaces-impl-1.2.3的Tomahawk-1.1.6(Geronimo为我提供了myFaces jar的实现,而我将战斧jar放在了应用)

"已解决":此问题是报告给myFaces论坛的问题。

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

编辑1

1.感谢凯尔·伦弗罗(Kyle Renfro)的迅速回应。在输入元素中使用的forceID属性在第一次不能使用,但是做了一些非常棘手的调整,我可以使&lt;t:message for =" xyz">标签起作用。

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

编辑2

好的,代码来了,希望它不会令人讨厌。

1.mainPage.jsp(这是&lt;t:panelTabbedPane>&lt;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.detail.jsp(这是&lt;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的后续行动时:

Kyle says:
  
  
    "At the first view of the page, if you press the "CREATE TICKET" button with nothing in any of the inputTexts and no files uploaded, do the message tags work for the inputTexts? (ie. required = true) I'm just curious if the messages for the inputTexts are working but the message for the inputFileUpload is not."

这是发现的行为:
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.

这是当我在生成的ID(例如ID" ticket_id")上看到" j_id_1"字时:

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">

解决方案

回答

战斧组件的forceId属性应该可以解决此问题。

就像是:

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

在页面的第一个视图中,如果我们按下" CREATE TICKET"按钮,而任何inputTexts中都没有任何内容,并且没有上传文件,那么消息标签是否适用于inputTexts? (即required = true)我只是想知道inputTexts的消息是否有效,而inputFileUpload的消息却无效。

回答

看起来可能与myfaces中的错误有关。我们可以尝试使用较新版本的myfaces和"战斧"。我将删除子视图功能,作为快速测试,将detail.jsp页面复制回主页。

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