I am using primefaces and p:inputText fields that are required, I use global p:messages to display the required info, and growl only from the back end bean. However, on check are displayed both the p:messages and the default p:growl error messages for required fields. Does anyone know how to disable the default growl messages?
<p:messages id="messages" autoUpdate="true"/>
<h:form id="addUser">
<p:growl id="newmessage" showDetail="false" globalOnly="true" />
<p:inputText id="name" value="#{manageUser.user.name}" required="true" />
and in my backing bean
if (uf.checkUsernameAvailability(user.getLogin())) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Error", "Username already exists!"));}
I don't understand why they keep appearing if they are not defined.
The p:growl and p:messages by default display all messages, or global only messages if the attribute is set.
However, both components have another nice attribute redisplay that you could use. Quote from the taglib documentation:
Defines if already rendered messages should be displayed. Default is
true.
Set this to false for the component that displays already rendered messages:
<p:growl id="newmessage" showDetail="false" globalOnly="true"
redisplay="false" />
Related
I'm new to JSF, my question may be silly for you.. It is very much valuable for me..
<h:form id="form1">
<p:messages autoUpdate="true" showDetails="true" />
<p:dataTable id='form1ID'>....</dataTable>
<p:inputText value="#{bean.name}" required="true"
requiredMessage="Please Enter Name!" label="Name ">
</p:inputText>
</h:form>
<h:form id="form2">
<p:messages autoUpdate="true" showDetails="true" />
<p:dataTable id='form2ID'>....</dataTable>
<p:inputText value="#{bean.name}" required="true"
requiredMessage="Please Enter Name!" label="Name ">
</p:inputText>
<p:commandButton value="Submit" update=":form1:form1ID"
actionListener="#{mgmtBean.doCreateType}" />
</h:form>
I have two forms. when I click on form2 command button with empty fields, it will show error messages perfectly since i have added <p:messages autoUpdate="true" showDetail="true"/>.
The bad thing or surprising thing here for me is, it is showing error messages on top of form1 also may be because of <p:messages autoUpdate="true" showDetail="true"/> added in form1 and i'm trying to update form1 on command button click in form2.
I don't want to show error messages on form1 when form2 is throwing validation error messages. How can i fix this ? I googled it out.. but couldn't find the solution.
Evironment i'm using is jsf-api-2.1.5 and primefaces 4.0 version and view technology is facelets(XHTML)
Hope it is clear..
Any idea is highly appreciated.
Try to disable rendering of messages on the form1:
<p:messages autoUpdate="true" showDetails="true" rendered="#{bean.renderedmessage}"/>
And in the bean, add the renderedmessage variable:
public Boolean getRenderedmessage() {
return renderedmessage;
}
/**
* #param renderedmessage the renderedmessage to set
*/
public void setRenderedmessage(Boolean renderedmessage) {
this.renderedmessage = renderedmessage;
}
And, for the doCreateType() method, add:
public void doCreateType(){
..............
setRenderedmessage(false);
.............
}
After the form1 is updated, you can choose some event or method, where you can setRenderedmessage(true);
What you're currently experiencing should indicate to you that you usually don't need two <p:messages/>s in the same JSF view; one is enough.
Regardless of the fact that you have two <h:form/>s on your page, there's still only one FacesContext associated with that view (The FacesContext object is a JSF construct that encapsulates all the information/data/components etc that's associated with a given JSF page request).
By default the <p:messages/> will display every FacesMessage that is queued within it's associated instance of FacesContext, regardless of the source of the message (well, almost: if you set globalOnly="true" on the <p:messages/>, you can change that behaviour).
That being said, you basically have two options:
Get rid of the extra <p:messages/> and rely on (and appropriately position) only one to display all errors/warnings for that view
Specify the for attribute, set to the desired component. Doing so, you'll guarantee that only one input component can trigger the display of its associated message component. For example
<h:form id="form1">
<p:messages for="inputName" autoUpdate="true" showDetails="true" />
<p:dataTable id='form1ID'>....</dataTable>
<p:inputText id="inputName" value="#{bean.name}" required="true"
requiredMessage="Please Enter Name!" label="Name ">
</p:inputText>
</h:form>
Note that I've set an id attribute on the <p:inputText/> component; this is necessary so you can use it in the for attribute for the messages component.
Further reading:
What is FacesContext used for?
I have fixed the issue by using the following code
<p:messages autoUpdate="true" showDetails="true" visibility="info"/>
so it is just displaying info messages and other pop up error messages will not be showun.
so i have this code(not in details)
<p:tabView id="tabviewId">
<p:tab>
<h:form id="mainHeadOfAccountsId_form">
// some input fields with validation
// using viewscoped
<p:commandButton value="Add" process="mainHeadOfAccountsId_form" update="mainHeadOfAccountsId_form :#{p:component('allMainHeadOfAccountsId_table')} :#{p:component('successfullySavedUpdatedId_growl')}" action="#{budgetHeadOfAccountsAction.addMainHeadOfAccountsOnAjax}" />
/// also using <p:datatable id= "allMainHeadOfAccountsId_table" >
</h:form
</p:tab>
<p:tab>
<h:form>
</h:form
</p:tab>
</p:tabView>
<p:growl id="successfullySavedUpdatedId_growl" for="successfullySavedUpdatedFor_growl" value="error" showDetail="false" />
my Question is that when i submit form mainHeadOfAccountsId_form successfully i need to update(reset) all fields which are in mainHeadOfAccountsId_form
but remember that i am also using <h:selectOneMenu> so i want to reset(option[0] selected) not empty, how can i do that ? currently its updating allMainHeadOfAccountsId_table and successfullySavedUpdatedId_growl except mainHeadOfAccountsId_form
i have tired tabviewId:mainHeadOfAccountsId_form but getting exception component not found,
as i am thinking this is just because of #viewScoped and i should reset value of those inputs in my action class (.java), m i right ?
see what primefaces offer for reset input or after submitting the form by the action in the bean reset the values by new or null and recreate the list held by
<h:selectOneMenu>
I have two forms in my page, in the first formulary are input fields with validation, and in the other a dataTable. The first formulary has a message area to show validation errors, and the second formulary has a message area to show problems with the retrieval of the data (this message area is updated from myController.search).:
<h:form id="form1">
<p:message id="messageForm1" for=":form1" />
<p:inputText id="text1" value="#{myBean.data}" required="true" />
....
<p:commandButton value="Search" actionListener"#{myController.search}"
update=":form2:dataTable :form2:messageForm2 :form1:messageForm1" process="text1, ..." />
</h:form>
<h:form id="form2">
<p:message id="messageForm2" for="messageForm2" />
<p:dataTable>
...
</p:dataTable>
</h:form>
The problem is that the messages in the form2 are working, but the validation messages in form1 are never shown
The description of the for attribute of the p:message tag says:
Id of the component whose messages to display.
So you can't specify the ID of the form. You have to specify the ID of a single form component. e.g. <p:message id="messageForm1" for="text1" />. But then you have to create one message element for every form component.
An alternative would be to use the p:messages tag. For examples see here: http://www.primefaces.org/showcase-labs/ui/messages.jsf
In my Facelets page I have this:
<p:growl id="msg1" life="1500"/>
and another
<p:messages id="msg2"/>
I need the following message to show up in <p:messages> only.
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("veillez saisir les champs obligatoires (*)", null));
But it also shows up in <p:growl>.
How do I specify where the message should show up?
Extracted from primefaces manual. Page 282.
Targetable Messages
There may be times where you need to target one or more messages to a specific message
component, for example suppose you have growl and messages on same page and you need to
display some messages on growl and some on messages. Use for attribute to associate messages
with specific components.
<p:messages for="somekey" />
<p:growl for="anotherkey" />
The Bean
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage("somekey", facesMessage1);
context.addMessage("somekey", facesMessage2);
context.addMessage("anotherkey", facesMessage3);
In sample above, messages will display first and second message and growl will only display the
3rd message.
Since p:messages is just extension for h:messages and p:growl is practically the same thing as h:messages you can't. What you can do is to not update p:growl after you add a message to context (probably you do that in some "confirm" commandButton) then it won't display at all, but you can't specify to display only some messages. Better solution is to not mix p:growl with p:messages and use only one.
The feature you are looking for will be available in new Primefaces 3.3 Targetable messages
Since you have already assigned 2 different IDs for <p:growl> and <p:messages>, I think you can try something like this:
<div id="aDiv">
### Use the following button to update only <p:growl id="msg1"> ###
<p:commandButton actionListener="#{mrBean.doSomething}" update="msg1" />
### Use the following button to update only <p:messages id="msg2"> ###
<p:commandButton actionListener="#{mrBean.doSomethingElse}" update="msg2" />
</div>
The key is that you should only update either msg1 or msg2, not both. In the above example, if your button has the attribute update="aDiv", your messages will be shown on both <p:growl> and <p:messages>.
You can use "Severity" Attribute of p:growl to specify which type of Messages you want to Show only in Growl.
<p:growl id="messages" severity="info, warn, error, fatal" showDetail="true" life="5200" autoUpdate="true" />
Now if you want to not to use Growl for info Messages then simply remove "info" perameter and then you can use either p:message or any text of your own choice and style it accordingly <p:outputLabel value="A Validation error occured!" rendered="#{facesContext.validationFailed}" />
So in this way you can use Growl and message according to your choice.
it's easy,here an example in
JSF + PrimeFaces 5.2
<p:messages for ="Message1" showDetail="true" autoUpdate="true" closable="true" />
<p:messages for ="Message2" showDetail="true" autoUpdate="true" closable="true" />
FacesContext.getCurrentInstance().addMessage("Message1", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "Hello 1"));
FacesContext.getCurrentInstance().addMessage("Message2", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "Hello 2"));
I'm getting this error java.util.NoSuchElementException when i tried to check one of my checkbox under h:selectManycheckBox when i submit the form.
The many checkbox is dynamically populated from the bean. Here is my code.
<h:form id="eF">
<h:inputText id="i" value="#{aklat.suggest}">
<a4j:support event="onkeyup" action="#{aklat.complete}" reRender="m"></a4j:support>
</h:inputText>
<s:div>
<h:selectManyCheckbox value="#{aklat.selectedBooks}" layout="pageDirection" id="m">
<s:selectItems value="#{aklat.books}" var="_book" itemLabel="#{_book}" itemValue="#{_book}" label="#{_book.bookName}"/>
</h:selectManyCheckbox>
<a4j:commandButton value="Add Users" action="#{aklat.fire}"></a4j:commandButton>
</s:div>
</h:form>
The weird part is it renders some data output but when i checked the source code. there are no input type checkbox element.
Is something I am missing.
I assume your managed bean is request scope...
because you are making an ajax request, you have to enable "aklat.books" to persist its value longer than request but shorther than session scope.
If you have tomahawk between your app libraries you can use savestate like this (put it after the h:form tag) :
<t:saveState value="#{aklat.books}"/>
if no tomahawk, you can use a4j:keepAlive:
<a4j:keepAlive beanName = "#{aklat.books}"/>