Add a message to p:messages using JavaScript - primefaces

I have a messages element on my page like this:
<p:messages id="messages" widgetVar="myMessages" showDetail="false" closable="true">
<p:autoUpdate/>
</p:messages>
I'd like to add a message using JavaScript. Looking at the docs,I should be able to do something like this:
PF('myMessages').appendMessage({detail:'Upload your files before saving',severity:'error'});
Or maybe like this:
PF('myMessages').add({detail:'Upload your files before saving',severity:'error'});
But I get a error that says "Uncaught TypeError: Cannot read properties of undefined (reading 'appendMessage')"

It's a bug in the primefaces 10 community download.
https://github.com/primefaces/primefaces/issues/7798

Related

Modified locale message of PrimeFaces is not working

I tried editing PrimeFaces locale message but the changes is not reflecting. I already check the widget of calendar in web console and the changes is already there. But still it uses the default message.
Calendar_en_US.js
PrimeFaces.locales['en_US'] = {
//other stuff
messages : {
..
'javax.faces.converter.DateTimeConverter.DATE_detail':'[E-WAR-0037][E-WAR-0037] {2}: \'{0}\' could not be understood as a date. Example: {1}',
..
};
and attached to page by
<h:outputScript library="js" name="${request.contextPath}/resources/js/calendar_en_US.js" />
and used it to calendar
<p:calendar widgetVar="issueDateVar" id="issueDate" pattern="yyyy-MM-dd" size="14" showOn="button" locale="en_US"
navigator="true" styleClass="#{maintainUi.requiredStyleClass}" onblur="transformVal(this);"
value="#{maintainUi.obj.IssueDate}"
disabled="#{maintainUi.readOnly}"/
The message error is still
Warrant Issue Date: '999' could not be understood as a date. Example: 2019-04-17
it Should be
[E-WAR-0037]Warrant Issue Date: '999' could not be understood as a date. Example: 2019-04-17
Starting from JSF 1.2, use the converterMessage attribute to replace the entire message.
I found my solution here
Custom Variables in JSF Converter's Error Message

Primefaces Datatable in nested TabView

I'm using pf4.0 and jsf 2.2 for my webapp. Now I have a nested TabView containing a second TabView with a datatable. Like this:
<p:tabView>
<p:tab>
<p:tabView>
<p:tab>
<p:dataTable>
....
</p:dataTable>
</p:tab>
</p:tabView>
...
the problem now is that if i use a filter in the datatable the following js error occurs:Uncaught TypeError: Cannot read property 'outerHeight' of undefined
Does anyone out there have a solution? Haven't found anything regarding to this problem :(
UPDATE:
I tried to reproduce the problem in an simple application and I found out, that this error only occures when scrollable=true and scrollHeight=250px is set.
Anyone got an idea?

How to open p:dialog inside a js file?

I want to open a p:dialog in a js file. My code is below:
<h:outputScript name="js/check.js"/>
<p:dialog id="dialog1" widgetVar="ex" >
</p:dialog>
In the js file I have written a function and inside that I have tried ex.show(); but it says ex is undefined.
Similarly I also want to invoke a p:commandButton in that file and I tried
document.getElementById("hformid:commandbuttonid").click(); and it says
document.getElementById("hformid:commandbuttonid") is null. How to solve it?
May be 'ex' is defined after your 'check.js' script is executed. Assuming your are using JQuery, try something like
$(document).ready ( function() {
ex.show();
});
So 'ex.show();' will be executed after the whole page is parsed.

Nested use of primefaces datalist and fieldset

Is it possible to use primefaces datalist and fieldset elements in a nested way. My application needs to look something like this:
<p:fieldset>
<p:dataList>
<p:fieldset>
<p:datalist>
</p:datalist>
</p:fieldset>
</p:dataList>
</p:fieldset>
I've tried it as mentioned above but I always get the following error:
javax.faces.view.facelets.TagException: /WEB-INF/flows/mainapp/wholesaleInfo.xhtml #106,105 Tag Library supports namespace: http://primefaces.org/ui, but no tag was defined for name: datalist
The datalist mentioned in the error message is of course the inner one... Any ideas how I could make that work? thanks Nikolaus
Try with dataList camelCase instead of datalist, in the inner one. This should make the error go away. However I am unsure if dataLists can be nested. If it's just for layout - display purpose, you may have a look at p:layout

Anchor tag on ICEfaces component

I'm looking for a way to set focus to an ICEfaces component by means of an anchor tag. For instance, when a field fails validation I want to output something like this:
Field XYZ failed validation
and then, at the XYZ component, have something like:
<ice:inputText id="XYZ" anchor="xyz">
This would enable the user to click on the error message and get focus on the offending component. Is this in any way possible? (I'm aware of the outputLink and inputLink component, but the error message would typically reside in a message.properties file making it hard to use components...)
I'm using ICEfaces version 1.8.2
Use labels. There they are for.
<h:outputLabel for="xyz">message</h:outputLabel>
<h:inputText id="xyz" />
Substitute with ice variants if necessary.