Please see this question (and answer) for the detailed idea. Here is a basic one (Please run this example, if it is possible to you. You can simple click on the label and start a (invalid!) file upload):
I got a <h:outputLabel>
to invoke an invisible <p:fileUpload>
. It is working fine. Now, the the error message of those is displayed above (Thanks to the answer provided by BalusC).
<h:form>
<b:commandButton id="c" value="Invoke me" ajax="true"
update="bootsfaces_message" action="#{bean.message}" />
<p:fileUpload id="file-input" widgetVar="file-input" update="@form"
auto="true" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" sizeLimit="10"
invalidSizeMessage="invalid size message"
fileUploadListener="#{bean.image}"
invalidFileMessage="invalid format" styleClass=" ui-helper-hidden" />
<h:outputLabel for="file-input_input"
onclick="PF('file-input').messageContainer.appendTo($('#bm'));">
LABEL
</h:outputLabel>
<h:outputText value="#{bean.file.fileName}" />
<br />
<h:outputText value="#{bean.file.size}" />
</h:form>
So for now, the error message is displayed, but with the theme of <p:message
>. But the message should always looks like a message from BootsFaces. You can compare it with a click on the button Invoke me
. Just add following code to a Manageed Bean
:
public void message() {
FacesContext.getCurrentInstance().addMessage(
"",
new FacesMessage(FacesMessage.SEVERITY_ERROR, null,
"test message"));
}
As pointed out in the answer, JavaScript is a possible solution to manipulate the DOM Tree. Well, that is not what I want (just the worst case solution).
Is there any BootsFaces specific solution for those kind of problems?