Say you have a table with a date column and you have created a view accessing it. Now try to insert an abnormal date into the dateInput field on the page (something like 1/1/111111111), commit the changes, check the value in the DB and you’ll get what I’m talking about here. I had queried a question on the OTN forum regarding this and the only answer I got was from Frank Nimphius to
which actually just checks that the Date attribute provided is of a logical range.
This method has to be part of a class extending oracle.jbo.server.EntityImpl and obviously the entity implementation for that table with a date column must extend the new EntityImpl class.
That's it. Hope this helps!
configure a value change listener on the date field and verify that the provided value is valid, If not call FacesContext.renderResponse to ignore the requestthis is a solution, but well, it requires more or less to apply it to each dateInput field on every single page. The other way around that I finally used, was to override the EntityImpl setAttributeInternal method like the following:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void setAttributeInternal(int attributeNumber, Object attributeValue) { | |
if (attributeValue instanceof oracle.jbo.domain. Date) { | |
java.util.Date value = ((oracle.jbo.domain.Date)attributeValue).getValue(); | |
GregorianCalendar gc = new GregorianCalendar(); | |
java.util.Date inAHundreedYears = new java.util.Date(new GregorianCalendar(gc.get(Calendar.YEAR) + 100, gc.get(Calendar.MONTH), gc.get(Calendar.DAY_OF_MONTH)).getTimeInMillis()); | |
if (value.after(inAHundreedYears)) { | |
System.err.println("Invalid date provided (" + value + ")"); | |
} | |
else { | |
super.setAttributeInternal(attributeNumber, attributeValue); | |
System.out.println("Set date " + value); | |
} | |
} | |
else { | |
super.setAttributeInternal(attributeNumber, attributeValue); | |
} | |
} |
which actually just checks that the Date attribute provided is of a logical range.
This method has to be part of a class extending oracle.jbo.server.EntityImpl and obviously the entity implementation for that table with a date column must extend the new EntityImpl class.
That's it. Hope this helps!
No comments:
Post a Comment