Store a Date in a DateTime field (and cleanup afterwards)


	//utility function to store a java.util.Date object in a document field (and recycle the DateTime object afterwards)
	public static void setDate( Document doc, String itemName, Date date) {
		
		DateTime dt = null;
		
		try {
			
			//get the current session object
			FacesContext facesContext = FacesContext.getCurrentInstance();
			Session session = (Session) facesContext.getApplication().getVariableResolver().resolveVariable(facesContext, "session");
			
			//construct a DateTime object and set it in the document field
			dt = session.createDateTime(date);
			doc.replaceItemValue(itemName, dt);
			
		} catch (NotesException e) {
			e.printStackTrace();
		} finally {
			try {
				dt.recycle();
			} catch (NotesException ne) { }
		}
		
	}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...