Posts Tagged ‘calendar’

Oracle ADF

Use Case – Create a custom validator to validate and To/From Date

Solution – 

JSPX – 

<?xml version=’1.0′ encoding=’UTF-8′?>
<jsp:root xmlns:jsp=”http://java.sun.com/JSP/Page” version=”2.1″
xmlns:f=”http://java.sun.com/jsf/core”
xmlns:h=”http://java.sun.com/jsf/html”
xmlns:af=”http://xmlns.oracle.com/adf/faces/rich”>
<jsp:directive.page contentType=”text/html;charset=UTF-8″/>
<f:view>
<af:document id=”d1″>
<af:form id=”f1″>
<af:panelFormLayout id=”pfl1″>
<af:inputDate label=”End Date” id=”endDate”>
<f:validator validatorId=”DateToFromValidator”/>
<f:attribute name=”startDate” value=”startDate”/>
</af:inputDate>
<af:commandButton text=”Submit” id=”cb1″/>
</af:panelFormLayout>
</af:form>
</af:document>
</f:view>
</jsp:root>

Validator – 

package view;

import java.util.Date;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import javax.faces.validator.Validator;

import javax.faces.validator.ValidatorException;

import oracle.adf.view.rich.component.rich.input.RichInputDate;

public class DateToFromValidator implements Validator{
public void validate(FacesContext facesContext, UIComponent uIComponent,
Object object) throws ValidatorException {
String dueDateComponentId = (String)uIComponent.getAttributes().get(“startDate”);
RichInputDate richInputDate =(RichInputDate) uIComponent.findComponent(dueDateComponentId);
Date startDate = (Date)richInputDate.getValue();
Date endDate = (Date)object;
String labelStartDate = richInputDate.getLabel();
String labelEndDate = ((RichInputDate)uIComponent).getLabel();
if((startDate == null)||(endDate == null)||(endDate.compareTo(startDate)<0)){
FacesMessage facesMessage = new FacesMessage();
facesMessage.setSummary(labelStartDate + “/”+ labelEndDate + ” Validation Error!”);
facesMessage.setDetail(labelStartDate + ” should be less than ” + labelEndDate);
facesMessage.setSeverity(facesMessage.SEVERITY_ERROR);
facesContext.addMessage(uIComponent.getId(), facesMessage);
}
}
}

Config File (Adfc-Config)- 

<?xml version=”1.0″ encoding=”windows-1252″?>

View original post 16 more words

This post is about some tricks to the  <af:calendar> component. For a detailed guide and tutorial to <af:calendar> you may follow these links:

Working with ADF Faces Calendar Component – An Oracle JDeveloper How To Document 

ADF Calendar Summary – oracle.adf.view.rich.component.rich.data.RichCalendar

To change the colors of the events in <af:calendar> we should override the activityStyles. In your managed bean create a HashMap variable and override its get() method as shown below:

private HashMap activityStyles = new HashMap<Set<String>, InstanceStyles>();

public HashMap getActivityStyles() {
try {
HashSet event1 = new HashSet<String>();
HashSet event2= new HashSet<String>();
HashSet event3= new HashSet<String>();

event1.add(“Milestone”);
event2.add(“Obligation”);
event3.add(“Task”);

activityStyles.put(event1, CalendarActivityRamp.getActivityRamp( CalendarActivityRamp.RampKey.PLUM ));
activityStyles.put(event2, CalendarActivityRamp.getActivityRamp( CalendarActivityRamp.RampKey.ORANGE ));
activityStyles.put(event3, CalendarActivityRamp.getActivityRamp( CalendarActivityRamp.RampKey.MIDNIGHTBLUE ));

} catch (Exception e) {
e.printStackTrace();
}
return activityStyles;
}

In calendar property:

activityStyles

 

In calendar activity attributes you have to select in Tags the property of your view object, based on which the colors are meant to change.

tags

 

The other calendar activities in the above photo are not relevant, you may have other names for your attributes.