Primefaces Calendar Setting Date Value in Backing Bean - jsf-2

I am using Primefaces inline (no popup) calendar on my JSF page. When the page is initially loaded, the calendar shows today's date. Initially the backing bean's value attached to calendar's date is empty. Now when I submit the form without selecting a date (no mouse select), the today's date value is not being set in backing bean. Isn't this a bug? Why am I forced to select a date when the date is already highlighted on a calendar when page is loaded?
Primefaces 3.4.2, JSF 2.2, Glassfish 4
<h:form id="calendarFormId">
<p:calendar id="calendarId" mode="inline" value="#{eventController.eventUI.date}" widgetVar="calendarWidget">
</p:calendar>
</h:form>

Related

PrimeFaces calendar change pattern after date selection

I use PrimeFaces calendar component on page. Pattern attribute is set to MM/dd/yyyy HH:mm:ss. Component value attribute is linked to java.util.Date variable in bean. When i open the page date in format which i expect, but after change of the value, format will always change into different format.
Expected format - 06/15/2015 08:00:30
Format after change of value - 06/15/2015 8:00 AM
Component ussage.
<p:calendar value="#{someBean.someJava.UtilDateVariable}" pattern="MM/dd/yyyy HH:mm:ss" locale="en">
<f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss"/>
</p:calendar>
I already tried to check primefaces showcase and documentation, different locale specification and also usage of the localization script for current localization but with no effect.
Every suggestion is welcome.
You do not need <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss"/>. This tag converts String to Object and viceversa.
The Primefaces documentation only uses the Pattern attribute and sometimes the locale attribute causes troubles.
Try:
<p:calendar value="#{someBean.someJava.UtilDateVariable}" pattern="MM/dd/yyyy HH:mm:ss"/>
I know this is old, but I had simalar problem, calendar showing right date, but when I opened the datepicker the pattern seemed to be wrong.
After three hours I ended it was bootstrap pattern.
To solve quickly I included a javascript file on the jsf page with setting for pattern:
In XHTML
<h:outputScript library="js" name="myscripts.js" />
IN JS
$(document).ready(function() {
$.fn.datepicker.defaults.format = "dd/mm/yyyy";
});

Grails:How to disable dates in calendar plugin

I' have 2 text fields 1st one for giving date from and the other one for date to, what i want is while i'm selecting date from using 'calendar:datePicker' the dates before current date must be disabled and if i have selected a date 1/6/2014 in 1st text field, when i select the date to from the 2nd one the dates before 1/6/2014 must be disabled how can i achive this..?
From<calendar:datePicker name="datefrom" years="${2014..2017}" value="${new Date()}" defaultValue="${new Date()}"/>
To<calendar:datePicker name="dateto" years="${2014..2017}" value="${new Date()}" defaultValue="${new Date()}"/>
That looks like an old plugin and it might not have the option that you need.
Use jQuery UI instead: http://jqueryui.com/datepicker/#date-range
jQuery UI has a grails plugin as well. http://grails.org/plugin/jquery-ui

Submitted value seems to be ignored

I have a selectOneMenu which is suposed to be processed when its value is changed.
The xhtml is quite generic so it's not very clear. Here it is:
<p:selectOneMenu
id="#{myId}"
value="#{obj[attr]}"
panelStyle="font-size: 10px;"
disabled="#{cc.attrs.grid.readonly}"
style="margin-top: 3px; width:79px;"
styleClass="#{change.getChangeClass(cc.attrs.grid)} toUpdate">
<f:selectItems value="#{cc.attrs.grid.valuesString}" var="elem" itemValue="#{elem}" itemLabel="#{elem}"/>
<f:validator validatorId="GenericValidator" />
<p:ajax
process="#this"
listener="#{rules.process()}"
update="#this"/>
Here is a part of the generated html which is clearer:
behaviors:{change:function(event){
PrimeFaces.ab({
source:'masterCenter:fuel3Content:j_idt621:fuel_codeCat',
event:'valueChange',
process:'masterCenter:fuel3Content:j_idt621:fuel_codeCat',
update:'masterCenter:fuel3Content:j_idt621:fuel_codeCat'}, arguments[1]);}
}
When I select a value, it gets posted (I can see with chrome tools that it is in the form data being posted).
But my validation method (GenericValidator.validate()) is not called.
When I submit the whole form, the validation method is called, but it indicates that the value of the combo is null.
I have the feeling that this value is not set as it should during the apply request values phase.
But this behaviour depends on the context:
This selectOneMenu is in a panel. The first time I open this panel (loaded with ajax), it works fine. I can change the value of the selectOneMenu and my validation method is called with the value that I've chosen.
Now when I open this panel again, the selectOneMenu doesn't work any more. However the generated html is exactly the same.
I also have the same behaviour with a p:inputTextarea in this form.
I'm using primefaces 3.4.1 with Mojarra 2.1.10. It looks to me like a primefaces/mojarra bug, but I haven't found notes of this problem.
in value expression value="#{obj[attr]}", why you are using a map? And how you set attr value? can you give more details?
In versions prior to jsf 2.0 validaton is ignored for empty and null fields. In jsf 2.0 if your jsf runs in environment where bean validation is supported then your empty or null fields are validated by default.
If you are using non j2ee 6 compliant servers like tomcat 6 or jetty in which bean validation is not supported then validation won't happen for null or empty fields.
If you want to enforce validation on empty fields you can use either required="true" or
<context-param>
<param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
<param-value>true</param-value>
</context-param>
Hope this helps. Leave a comment if you need further help

h:dataTable nested in ui:repeat, updating of inputText values not working

I render an ArrayList (menu.specifications) containing custom objects (POJOs) in several h:dataTables on the same page. Each h:dataTable contains a different range of the elements of the ArrayList. One column contains an h:inputText tag.
After user input and submit, only the inputText tags of the last dataTable are updated. The others
remain unchanged.
Here is the relevant code:
<h:form>
<ui:repeat value="#{menu.groupTitles}" var="element" varStatus="loop">
<h:dataTable rendered="#{menu.points[loop.index].y>0}" value="#{menu.specifications}"
first="#{menu.points[loop.index].x}" rows="#{menu.points[loop.index].y}" var="rowVar" border="1">
<h:inputText value="#{rowVar.pvalue}" id="pvalue"/>
I tried this as well:
<h:inputText value="#{menu.specifications[rowVar.index].pvalue}" id="pvalue"/>
Explanation of references:
menu.points[loop.index].x = first element of the ArrayList to show in the dataTable
menu.points[loop.index].y = number of elements to show in the dataTable
menu.groupTitles = titles of the different dataTables
This seems to be an issue by the dataTables all having the same ID when generated by a ui:repeat tag. See also this issue at the Mojarra JIRA. However, I don't have a solution yet. It seems to exist since the JSF 1.2 days, because the problem first occured when switching from JBoss 4.2.2 to 4.3.3 which included a JSF 1.2 version upgrade as well.

Groovy/Grails: How do I make my datePicker blank or null by default instead of showing today's date?

That is basically my question. It is showing me today's date and not a blank or null or '' date, even if I put null or '' it runs perfectly but keeps showing me today's date, not a blank dropdown box. So I want to change the default to being blank when the gsp loads, not with today's date.
Thanks
The usage of the attribute default is not documented in the Grails documentation but its functionality can be extracted from the implementation. Use the attribute default="none"to stop the datePicker from using the current date and provide an empty text as the noSelection value:
<g:datePicker default="none" noSelection="['':'']" />
More information about the attribute noSelection can be found in the Grails documentation.

Resources