Rectangle 27 6

As shown in the Showcase:

<script type="text/javascript">
    // <![CDATA[
    var curDt = new Date();
    disableBeforeToday = function(day) {
        return (curDt.getTime() - day.date.getTime() < 0);
    }
    // ]]>
</script>


<rich:calendar dayDisableFunction="disableBeforeToday" >
&...;

I didn't saw this showcase, it's not the same as the current showcase. Thank you for your answer and sorry if I bother you with something that already was explained in the showcase.

It's not the same but disabling the days before today is part of the showcased code. And you're not bothering, I'm linking to showcase more to show where I got it from than to show you you were not looking hard enough ;)

perfect! it works like a charm!

jsf - How disable date selection for previous days in RichFaces Calend...

jsf jsf-2 calendar richfaces
Rectangle 27 6

As shown in the Showcase:

<script type="text/javascript">
    // <![CDATA[
    var curDt = new Date();
    disableBeforeToday = function(day) {
        return (curDt.getTime() - day.date.getTime() < 0);
    }
    // ]]>
</script>


<rich:calendar dayDisableFunction="disableBeforeToday" >
&...;

I didn't saw this showcase, it's not the same as the current showcase. Thank you for your answer and sorry if I bother you with something that already was explained in the showcase.

It's not the same but disabling the days before today is part of the showcased code. And you're not bothering, I'm linking to showcase more to show where I got it from than to show you you were not looking hard enough ;)

perfect! it works like a charm!

jsf - How disable date selection for previous days in RichFaces Calend...

jsf jsf-2 calendar richfaces
Rectangle 27 0

You can use dayDisableFunction attribute of rich:calendar if you want to restrict the user not to select the date earler than your initial date.

<rich:calendar isDayEnabled="disableBeforeInitialDay" >

and you can have javascript function like

function disableBeforeInitialDay(day)  {
   Date initialDay = new Date(2014,1,27); //equals to 27th Feb 2014  
   return (initialDay.getTime() - day.date.getTime() < 0);  
}

The above code disables all the dates earlier than your initial date.

<rich:calendar .....>  
    <f:validator validatorId="myDateValidator" /> 
 </rich:calendar>  

@FacesValidator("myDateValidator")
public class MyDateValidator implements Validator {  
      @override
      public void validate(FacesContext context, UIComponent comp, Object value) throws    
       ValidatorException {

           Date date = (Date) value;
           Date refDate = new Date(2014,1,27);  
           if (date.before(refDate )) {
               String message = "Date is earlier than initial date.";
               throw new ValidatorException(new FacesMessage(message));
           }  
       }  
  }

If you are using richfaces 4.X the attribute should be dayDisableFunction Hope this helps

Thanks for your reply Srikanth, I'm making your second option but I have a problem, how I get the initial Date from my ManagedBean or other componentUI??. Because I test your example and it works fine! but I need to get date (refDate in your example) dinamically from MB or ComponentUI. Thanks!

you can put as a request parameter using <f:param name="initialdate" value="#{valueMB.initialDate}" and you can access it from FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(initialdate); There are other ways also you can see simple examples of them here mkyong.com/jsf2/

@Candres I feel the better approach will be to add attribute to the calendar. You can do like this <f:attribute name="initialdate" value="#{valueMB.initialDate}" /> as a child tag to the rich:calendar. You can access it in the validator as String param = (String) component.getAttributes().get("initialdate"); In this approach no need to use FacesContext.

Thank you sooo Much Srikanth! it works like a charm!! I add the f:attribute as you indicate above and I get the parameter easily with component.getAttributes().get("initialdate") .. Thanks again man!

You are welcome :)

java - Set start date in Calendar RichFaces - Stack Overflow

java jsf calendar richfaces
Rectangle 27 0

Use the isDayEnabled="isDayEnabled" attribute, where the value (isDayEnabled) is a javascript function you should define, in the form

function isDayEnabled(day) {
}

If you want to add validation on the server side, use a custom JSF Validator, or use Hibernate Validator annotations (see richfaces - bean validator)

Can this be done on the server side? I do not want to use javascript. I would have to implement extra validations on the server!

implement the validation on the server manually. Using custom JSF Validator. Or, using Hibernate Validator annotations (see richfaces - bean validator)

jsf - Richfaces Calendar Minimum and Maximum Dates - Stack Overflow

jsf richfaces
Rectangle 27 0

The "defaultTime" attribute to set the default time value for the current date in two cases:

  • If another date is selected and the value of the "resetTimeOnDateSelect" attribute is set to "true"

date - richfaces calendar today - Stack Overflow

date calendar richfaces
Rectangle 27 0

You cannot select more than one date (<rich:calendar/> serves as input for a date field), you can however colorize some days in a different way than others. These are your options:

To pass the dates to the javascript function, your server side should generate appropriate JavaScript code, for example:

<script type="text/javascript">
    highlightDates = new Array();
    #{myComponent.dateList}
</script>
MyComponent
@Named("myComponent")
public class MyComponent implements Serializable {

    // The list of dates to highlight, taken from somewhere
    private List<Date> dates;

    public String getDateList() {
        StringBuilder sb = new StringBuilder();
        // Iterate the list of dates and add a javascript push
        // for each date and return the resulting string.
        for (Date d : dates) {
            sb.append("highlightDates.push(new Date(");
            sb.append(d.getTime());
            sb.append(");\n");
        }
        return sb.toString();
    }
}

An example of how the javascript function dayStyleClass="dayFunc" works follows. This assumes you have jQuery (richfaces requires it) and used the noconflict() function. We use the jQuery.inArray function, which returns the index of the value in an array, or -1 if the value is not in the array:

function dayFunc(day) { 
    return jQuery.inArray(day, highlightDates) >= 0 ? 'highlighted' : 'normal'; 
}

The JavaScript code will work only if OP uses Facelets in his/her project.

@LuiggiMendoza: you're right

@EmirCalabuch: Hi thank you very much for the answer. I tried it and I still have several points to clear. 1. What do you mean by "a javascript function that takes a 'day' parameter"? You meant I should call the function like this? dayStyleClass="dayFunc(day)" 2. How do I use 'highlightDates' array in my function?

@prageeth: edited the answer to include an example of the javascript function.

richfaces - Rich Calendar - Highlight selected dates - Stack Overflow

richfaces seam
Rectangle 27 0

I created a class which implements the CalendarDataModel.

CalendarDataModel
preloadDateRangeStart
preloadDateRangeEnd

My CalendarDataModel disables calendar items whose date is out of the date range I specified in a property file and which I use in the CalendarDateModel to determine if the item's date is not between the range in order to disable it.

So now it works great. Here is the tag:

<a4j:outputPanel id="myCal" layout="block">
   <rich:calendar cellHeight="30px" cellWidth="30px" 
       dataModel="#{MyCalendarDataModel}" datePattern="dd/MM/yyyy" mode="ajax"
       style="width:200px" value="#{MyPage.theDate}"/>
 </a4j:outputPanel>

I also tried your solution. It works but it's a bit messy on the client.

Could you please post the Java code to your implementation of CalendarDataModel?

Lazlo I do not have the code. I changed job. Look at the actual implementation java2s.com/Open-Source/Java-Document/JBoss/ and make your changes man. Your name looks like a UUID version 5.

jsf - Richfaces Calendar Minimum and Maximum Dates - Stack Overflow

jsf richfaces
Rectangle 27 0

String date = "15-09-2011:23:30:45";//your date
    DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy:HH:mm:SS");
    Date convertedDate = (Date) formatter.parse(date);
main()

jsf - I have calendar in the page, but property in the bean is a Strin...

jsf date calendar richfaces
Rectangle 27 0

Use the isDayEnabled="isDayEnabled" attribute, where the value (isDayEnabled) is a javascript function you should define, in the form

function isDayEnabled(day) {
}

If you want to add validation on the server side, use a custom JSF Validator, or use Hibernate Validator annotations (see richfaces - bean validator)

Can this be done on the server side? I do not want to use javascript. I would have to implement extra validations on the server!

implement the validation on the server manually. Using custom JSF Validator. Or, using Hibernate Validator annotations (see richfaces - bean validator)

jsf - Richfaces Calendar Minimum and Maximum Dates - Stack Overflow

jsf richfaces
Rectangle 27 0

I created a class which implements the CalendarDataModel.

CalendarDataModel
preloadDateRangeStart
preloadDateRangeEnd

My CalendarDataModel disables calendar items whose date is out of the date range I specified in a property file and which I use in the CalendarDateModel to determine if the item's date is not between the range in order to disable it.

So now it works great. Here is the tag:

<a4j:outputPanel id="myCal" layout="block">
   <rich:calendar cellHeight="30px" cellWidth="30px" 
       dataModel="#{MyCalendarDataModel}" datePattern="dd/MM/yyyy" mode="ajax"
       style="width:200px" value="#{MyPage.theDate}"/>
 </a4j:outputPanel>

I also tried your solution. It works but it's a bit messy on the client.

Could you please post the Java code to your implementation of CalendarDataModel?

Lazlo I do not have the code. I changed job. Look at the actual implementation java2s.com/Open-Source/Java-Document/JBoss/ and make your changes man. Your name looks like a UUID version 5.

jsf - Richfaces Calendar Minimum and Maximum Dates - Stack Overflow

jsf richfaces
Rectangle 27 0

Why do you have both value and component binding on the calendar pointing to the same el expression ? You cannot do componentbinding on a richfaces calendar with type date.

Also, have you tried using ui:repeat instead of c:foreach ?

c:foreach is known to give problems in a facelets context related to the jsf and jsp lifecycle mismatch. Have a look at the post above for more info.

Thanks, ddewaele. I'm going to use ui:repeat instead of the c:foreach.

java - JSF throws argument type mismatch when binding - Stack Overflow

java jsf binding richfaces
Rectangle 27 0

As shown in the Showcase:

<script type="text/javascript">
    // <![CDATA[
    var curDt = new Date();
    disableBeforeToday = function(day) {
        return (curDt.getTime() - day.date.getTime() < 0);
    }
    // ]]>
</script>


<rich:calendar dayDisableFunction="disableBeforeToday" >
&...;

I didn't saw this showcase, it's not the same as the current showcase. Thank you for your answer and sorry if I bother you with something that already was explained in the showcase.

It's not the same but disabling the days before today is part of the showcased code. And you're not bothering, I'm linking to showcase more to show where I got it from than to show you you were not looking hard enough ;)

perfect! it works like a charm!

jsf - How disable date selection for previous days in RichFaces Calend...

jsf jsf-2 calendar richfaces
Rectangle 27 0

You can use mask on an input field, you have the example in the showcases http://www.primefaces.org/showcase/ui/input/calendar.xhtml, try the example with the mask label and note the

<p:outputLabel for="mask" value="Mask:" />
<p:calendar id="mask" value="#{calendarView.date9}" pattern="dd-MM-yyyy" mask="true" />

insded the xhtml. Your' mask would of course be

<p:outputLabel for="mask" value="Mask:" />
    <p:calendar id="mask" value="#{calendarView.date9}" pattern="dd/MM/yyyy" mask="true" />

not 100% what you need, but this is as far as you'll get using primefaces only.

date - Rich calendar automatic "/" sign in input - Stack Overflow

date primefaces calendar richfaces
Rectangle 27 0

Following code sets date from first calendar to second and rerender second calendar component. Code not sets today date for second calendar. System date is used as today date and it is the same date for first and second calendars. Code:

<h:panelGrid columns="2">
        <h:outputLabel for="from" value="From" />
        <rich:calendar id="from" value="#{t1Calendar.from}"
            datePattern="dd/MM/yyyy" enableManualInput="true">
            <a4j:ajax event="change" render="to"/>
        </rich:calendar>

        <h:outputLabel for="to" value="To" />
        <rich:calendar id="to" value="#{t1Calendar.to}"
            datePattern="dd/MM/yyyy" enableManualInput="true" popup="true"/>
    </h:panelGrid>

and

@ManagedBean
public class T1Calendar {
    private Date from = new Date();
    private Date to;

    public Date getFrom() { return from; }
    public void setFrom(Date from) {
        this.from = from;
        this.to = from;
    }
    public Date getTo() { return to; }
    public void setTo(Date to) { this.to = to; }

}

Richfaces Calendar Today Date - Stack Overflow

calendar richfaces
Rectangle 27 0

You can use dayDisableFunction attribute of rich:calendar if you want to restrict the user not to select the date earler than your initial date.

<rich:calendar isDayEnabled="disableBeforeInitialDay" >

and you can have javascript function like

function disableBeforeInitialDay(day)  {
   Date initialDay = new Date(2014,1,27); //equals to 27th Feb 2014  
   return (initialDay.getTime() - day.date.getTime() < 0);  
}

The above code disables all the dates earlier than your initial date.

<rich:calendar .....>  
    <f:validator validatorId="myDateValidator" /> 
 </rich:calendar>  

@FacesValidator("myDateValidator")
public class MyDateValidator implements Validator {  
      @override
      public void validate(FacesContext context, UIComponent comp, Object value) throws    
       ValidatorException {

           Date date = (Date) value;
           Date refDate = new Date(2014,1,27);  
           if (date.before(refDate )) {
               String message = "Date is earlier than initial date.";
               throw new ValidatorException(new FacesMessage(message));
           }  
       }  
  }

If you are using richfaces 4.X the attribute should be dayDisableFunction Hope this helps

Thanks for your reply Srikanth, I'm making your second option but I have a problem, how I get the initial Date from my ManagedBean or other componentUI??. Because I test your example and it works fine! but I need to get date (refDate in your example) dinamically from MB or ComponentUI. Thanks!

you can put as a request parameter using <f:param name="initialdate" value="#{valueMB.initialDate}" and you can access it from FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(initialdate); There are other ways also you can see simple examples of them here mkyong.com/jsf2/

@Candres I feel the better approach will be to add attribute to the calendar. You can do like this <f:attribute name="initialdate" value="#{valueMB.initialDate}" /> as a child tag to the rich:calendar. You can access it in the validator as String param = (String) component.getAttributes().get("initialdate"); In this approach no need to use FacesContext.

Thank you sooo Much Srikanth! it works like a charm!! I add the f:attribute as you indicate above and I get the parameter easily with component.getAttributes().get("initialdate") .. Thanks again man!

You are welcome :)

java - Set start date in Calendar RichFaces - Stack Overflow

java jsf calendar richfaces