在JSP页面中,我创建了
<h:form enctype="multipart/form-data">
具有一些元素:
<t:inputText>
,
<t:inputDate>
等等。此外,我添加了一些
<t:message for="someElement">
我想允许用户在表单中上传几个文件(一次一个)(使用
<t:inputFileUpload>
)此时,我的代码运行良好。
当我试图把表格放在
<t:panelTabbedPane serverSideTabSwitch="false">
(当然,在
<t:panelTab>
)
我从中复制了TabbedPane示例的源代码中显示的结构
Tomahawk's examples
,通过使用
<f:subview>
标记,并将panelTab标记放入一个新的jsp页面中(使用
<jsp:include page="somePage.jsp">
指令)
首先
<t: inputFileUpload>
无法按照Managed Bean UploadedFile属性中指定的值加载文件
#{myBean.upFile}
然后
googling for a clue
,我就知道
<t:panelTabbedPane>
生成一个名为“自动表单”的表单,所以我得到了嵌套表单。好的,我修复了创建
<h:form>
中的
<t: 面板选项卡窗格>
还有尤里卡!文件输入再次工作!(自动成型不会生成)
但是,哦,惊喜!哦,可怕的墨菲定律!我所有的
<h:message>
开始失败。Eclipse控制台的输出显示
<t:message>
正在寻找不存在的元素ID(这些元素的ID部分等于他们正在寻找的ID,但在ID的末尾,他们的名称会更改)
在这一点上,我提出了
<t:mesagges>
标记(注意末尾的“s”),以便在Panel的开头一次向我显示所有验证错误,并且它运行良好。因此,验证错误是存在的,并且在小组开始时正确显示。
该页面中生成的所有验证错误消息都是JSF内置的验证消息。此时的backingbean还没有定义任何验证器。
我怎样才能拿到
<t:message for="xyz">
工作正常吗?
我在eclipse Ganymede项目中使用Tomahawk-1.1.6和myFaces-impl-1.23,该项目使用Geronimo作为应用服务器(Geronimo为我提供了myFaces-jar实现,而我将Tomahawk-jar放在应用程序的WEB-INF/lib文件夹中)
“已解决”:这个问题已报告给myFaces论坛。
感谢Kyle Renfro的快速回复和信息。(干得好,凯尔!)
See the issue
编辑1
1.-感谢Kyle Renfro的迅速回应。input元素中使用的forceID属性第一次不起作用,但在进行一些非常棘手的调整时,我可以
<t: =“xyz”的消息>
标记有效。
我所做的是:
1.有我的标签
<inputText id="name" forceId="true" required="true">
这个
<t: 消息>
不起作用。
2.然后,在eclipse控制台上查看了错误消息后,我将我的“id”属性重命名为:<inputText id=“
名称j_id_1
“forceId=”true“required=”true“>
3.然后
<t: 消息>
成功了!!但在第二次按下表格的“提交”按钮后。第二次!(我怀疑JSF生命周期中发生了一些事情)
4.这意味着用户必须按两次提交按钮才能在页面上获得错误消息。
5.在id末尾使用“j_id_1”短语非常奇怪。
编辑2
好的,代码来了,希望它不会令人讨厌。
1-
主页.jsp
(这是
<t: 面板选项卡窗格>
和
<f: 子视图>
标签)
<%@ 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
(这是
<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说:
“在页面的第一个视图中,如果您在任何inputText中没有任何内容,也没有上载任何文件的情况下按下”CREATE TICKET“按钮,那么消息标签对inputText有效吗?(即required=true)我只是想知道inputText的消息是否有效,而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”atribute进行删减):
<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">