How to increment +1 day in mindate of <p:calendar> - jsf

I need to add +1 day in mindate (or) I don't want to accept the condition as in the image, effective date and expiration date as same.
Here is the code:
<p:calendar id="Jurisdiction_Expiration_Date"
styleClass="calender_style" pattern="MM/dd/yyyy"
required="true" size="10" readonlyInput="true" showOn="both"
mindate="#{ApplicationManagedBean23.saveRequestMap['JurisdictionEffectiveDate']}">

Couple of things here:
p:calendar is deprecated. Please use p:datePicker.
Use value-binding as demonstrated in the basic example: https://www.primefaces.org/showcase/ui/input/datepicker/datePickerJava8.xhtml
Use a modern Java 8 date (only) type like LocalDate which makes it easy to add a day: localDate.plusDays(1).
Add an Ajax listener where you set the min date based on the changed value and update the component with the min date (which you bind to the bean property).
Make sure you are using the correct bean scope.
See also:
Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
How to choose the right bean scope?

Related

How to use <p:spinner with attribut max=current year

I want to use <p:spinner where attribut max equals current year in jsf but without using backend bean.
I use jsf 2.
thanks.
You can use #{now} from OmniFaces http://showcase.omnifaces.org/managedbeans/now
Example:
#{of:formatDate(now, 'yyyy')}

How to get current year in jsf without using backend bean [duplicate]

Is it possible to display the current date (today's) in JSF without using a backing bean?
I have the following code snippet , but it didn't work out.
<div class="leftSide">Today's date #{currentDate}</div>
or
<f:facet name="header">
<h:outputText value="Today's date" />
</f:facet>
<h:outputText value="#currentDate">
<f:convertDateTime pattern="MM/dd/yyyy" type="date" />
</h:outputText>
You could register an instance of java.util.Date as a request scoped bean in faces-config.xml.
<managed-bean>
<managed-bean-name>currentDate</managed-bean-name>
<managed-bean-class>java.util.Date</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
This way it's available as #{currentDate} without the need for a custom backing bean class.
Update: the JSF utility library OmniFaces has such a bean already registered as #{now}. So if you happen to use OmniFaces already, you can just make use of it directly.
<h:outputText value="#{now}">
<f:convertDateTime pattern="MM/dd/yyyy" type="date" />
</h:outputText>
In JSF you could use the implicit EL object session that provides access to the current HttpSession. The HttpSession#getLastAccessedTime time ...
... returns the last time the client sent a request associated with this
session, as the number of milliseconds since midnight January 1, 1970
GMT, and marked by the time the container received the request.
So you could use the following code snippet in your facelet:
<h:outputText value="#{session.lastAccessedTime}">
<f:convertDateTime pattern="MM/dd/yyyy" type="date" />
</h:outputText>
This will be server time and may differ from client time with respect to different time zones.
But you could also use a javascript solution, as discussed here:
How do I get the current date in JavaScript?
Or you could do it using Omnifaces. I'm surprised BalusC hasn't told you about this solution (I think he's a great Omnifaces contributor). Maybe it's because using Omnifaces just to display a simple date in a page might be an overkill to some.
Anyway, if your project already uses Omnifaces, there are 2 managed beans exposed by default and one in particular that you may find handy. As per the tag documentation specifies, once Omnifaces is added to your project, you can use the #{now} managed bean.
For instance, to set a Primefaces calendar's max date, I just wrote the following :
<p:calendar id="myCalendar" pattern="dd/MM/yyyy"
value="#{mybean.myDate}" maxdate="#{now}"/>
I guess the #{now} managed bean can be used in many more situations, and probably yours as well.
If your project does not use Omnifaces yet, I suggest you look at their spec and see how helpful it could be for you.
For instance, I'm using their validateOrder tag to make sure two dates are properly ordered.
You can use the tag which PrimeFaces provide.
<p:clock pattern="HH:mm:ss dd-MM-yyyy"/>

<h:selectOneMenu> value change listener invoked for all dropdowns instead of only the current

I'm using MyFaces 1.1. I have two <h:selectOneMenu>s dropdowns which each point to same valueChangeListener method.
<h:selectOneMenu id="d1" value="#{mybean.selectedChannel1}"
onchange="submit()" valueChangeListener="#{myform.channelValuechange}">
<f:selectItems value="#{mybean.channelList}"/>
</h:selectOneMenu>
<h:selectOneMenu id="d2" value="#{mybean.selectedChannel2}"
onchange="submit()" valueChangeListener="#{myform.channelValuechange}">
<f:selectItems value="#{mybean.channelList}"/>
</h:selectOneMenu>
When I change the first dropdown, then the value change listener method get fired correctly. In the method, I'm obtaining the ID of the current component as sourceId via ValueChangeEvent argument and then comparing it as follows:
if (sourceId.equals("d1")) {
// ...
} else if (sourceId.equals("d2")) {
// ...
}
However, my concrete problem is that d2 block is also called when d1 is changed.
I tried the one and other and figured that the following helped to solve the problem:
if (!event.getPhaseId().equals(PhaseId.INVOKE_APPLICATION)) {
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
event.queue();
}
However, I don't feel like that it's the best solution. How is this caused and how can I solve it without using the above code?
With onchange="submit()" you're basically submitting the entire form when the current input element is changed, not only the currently changed input! In contrary to what many starters incorrectly think, there is no means of any input-specific JavaScript/Ajax magic here. As you're submitting the entire form, it would trigger the processing of all input components.
The valueChangeListener is always invoked when the submitted value of the input component does not equals() the initial model value as in the backing bean. Given that in your case both menus hit the value change listener when you change only the first one, that can only mean that the default select item value of the second menu does not equals() the initial model value in the backing bean.
You need to make sure that #{mybean.selectedChannel2} of the second menu has by default exactly the same value as the first item of #{mybean.channelList} of the second menu's list. This way the value change listener won't be invoked for the second menu when you change the first menu.
See also:
When to use valueChangeListener or f:ajax listener? (just to learn what's different in JSF 2, for the case you're interested)

richfaces 3.3.3 rich:calendar how to set input field to today date?

I have the following code:
<rich:calendar id="DocFromDate" locale="bg" firstWeekDay="1"
value="#{ioPageBeanParam.editBean.data['DocFromDate']}"
datePattern="dd.MM.yyyy HH:mm" />
This displays empty input field and calendar icon.
I would like to pre-fill the input field with today's date.
Searched trough documentation richfaces 3.3.3
But did not find the way to get and set currentDate. Is it possible in this component?
Initialize it in your bean. In the constructor of your bean set the value to today.

Get current time by default from rich:calendar in Richfaces 3.3.X?

When I use the rich:calendar object with time, it automatically defaults the time to noon on all selected dates. Here is the relevant code:
<rich:calendar id="dateAndTimeWithDefault"
required="true"
value="#{fooHome.instance.dateAndTimeWithDefault}"
datePattern="MM/dd/yyyy hh:mm a"
validator="#{utilities.dateBeforeCurrent}"/>
Is there any way to easily default the selected time to the actual time instead of 12:00PM?
I'm using RichFaces version 3.3.2.
Thanks!

Resources