Hi people:
In a JSP page, I created a <h:form enctype="multipart/form-data">
with some elements: <t:inputText>
, <t:inputDate>
, etc. Also, I added some <t:message for="someElement">
And I wanted to allow the user upload several files (one at a time) within the form (using <t:inputFileUpload>
) At this point my code works fine.
The headache comes when I try to put the form inside a <t:panelTabbedPane serverSideTabSwitch="false">
(and thus of course, inside a <t:panelTab>
)
I copied the structure shown in the source code for TabbedPane example from Tomahawk's examples, by using the <f:subview>
tag and putting the panelTab tag inside a new jsp page (using <jsp:include page="somePage.jsp">
directive)
First at all, the <t:inputFileUpload>
fails to load the file at the value assigned in the Managed Bean UploadedFile attribute #{myBean.upFile}
Then, googling for a clue, I knew that <t:panelTabbedPane>
generates a form called "autoform", so I was getting nested forms. Ok, I fixed that creating the <h:form>
out of the <t:panelTabbedPane>
and eureka! file input worked again! (the autoform doesn't generate)
But, oh surprise! oh terrible Murphy law! All my <h:message>
begins to fail. The Eclipse console's output show me that all <t:message>
are looking for nonexistents elements ID's (who have their ID's in part equals to they are looking for, but at the end of the ID's their names change)
At this point, I put a <t:mesagges>
tag (note the "s" at the end) to show me all validation errors at once at the beginning of the Panel, and it works fine. So, validation errors exists and they show properly at the beginning of the Panel.
All validation error messages generated in this page are the JSF built-in validation messages. The backing bean at this moment doesn't have any validators defined.
¿How can I get the <t:message for="xyz">
working properly?
Thanks in advance.
I'm using Tomahawk-1.1.6 with myFaces-impl-1.2.3 in a eclipse Ganymede project with Geronimo as Application Server (Geronimo gives me the myFaces jar implementation while I put the tomahawk jar in the WEB-INF/lib folder of application)
"SOLVED": This problem is an issue reported to myFaces forum.
Thanks to Kyle Renfro for the soon response and information. (Good job Kyle!) See the issue
EDIT 1
1.- Thanks to Kyle Renfro for his soon response. The forceID attribute used inside the input element doesn't works at first time, but doing some very tricky tweaks I could make the <t:message for="xyz">
tags work.
What I did was:
1. Having my tag <inputText id="name" forceId="true" required="true">
The <t:message>
doesn't work.
2. Then, after looking the error messages on eclipse console, I renamed my "id" attribute to this: <inputText id="namej_id_1" forceId="true" required="true">
3. Then the <t:message>
worked!! but after pressing the "Submit" button of the form the second time. ¡The second time! (I suspect that something is going on at the JSF lifecycle)
4. This implies that the user have to press 2 times the submit button to get the error messages on the page.
5. And using the "j_id_1" phrase at the end of IDs is very weird.
EDIT 2
Ok, here comes the code, hope it not be annoying.
1.- mainPage.jsp (here is the <t:panelTabbedPane>
and <f:subview>
tags)
<%@ 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 (here is the <t:panelTab>
tag)
<%@ 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>
EDIT 3
On response to Kyle Renfro follow-up:
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."
Here is the behavior found:
1.- There is no validation error messages shown at all (the message tags don't work) Even when I try to test only one validation error message (for example, testing the message for the first input text) none of them shows up.
2.- The eclipse console shows me these internal errors:
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.
Here is when I saw the "j_id_1"
word at the generated IDs, for example, for the 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
And, viewing the resulting HTML generated page, I saw that the IDs names are like this (whitout using "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">