| Author |
unable to type case
|
nikhil katoch
Greenhorn
Joined: Jun 09, 2012
Posts: 10
|
|
greetings!!
i am using a converter in which getAsString is defined as
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
SimpleDateFormat format=new SimpleDateFormat("dd/MMM/yyyy");
Calendar cal=(Calendar)arg2; //////////////line of error
Date t=cal.getTime();
String s=format.format(t);
return (s);
}
this is applied to a field that display a calender data. so arg2 is a calendar data but on running the code error say
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.GregorianCalendar
but arg2 is already a calender data (i have also tried to print arg2 by using getAsString and it gives calendar data ). so why is it giving this type cast error???
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14571
|
|
http://www.coderanch.com/how-to/java/UseCodeTags and your code samples will be easier to read.
I think you may discover that more than one type of data is being passed as arg2 and that you'll need to determine which type arg2 has as part of the conversion function so that the appropriate conversion code (including type-casting) can be selected and executed.
It's also possible that you've configured your converter to convert one or more non-Calendar properties.
Incidentally, I think that the standard JSF date converter handles both Date and Calendar objects, so you might not actually need a custom converter.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
nikhil katoch
Greenhorn
Joined: Jun 09, 2012
Posts: 10
|
|
well i tried standard converter
<f:convertDateTime dateStyle="full"/> also <f:convertDateTime pattern="mm/dd/yyyy"/>
but it gives error
Servlet.service() for servlet Faces Servlet threw exception
javax.servlet.jsp.JspException: Not nested in a tag of proper type. Error for tag with handler class:com.sun.faces.taglib.jsf_core.ConvertDateTimeTag.
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14571
|
|
|
Could you show us the surrounding tag as well as the converter tag?
|
 |
nikhil katoch
Greenhorn
Joined: Jun 09, 2012
Posts: 10
|
|
</h:column>
<h:column id="column5">
<f:facet name="header">
<h:outputText value="Issued on"></h:outputText>
</f:facet>
<h:outputText value="#{row.from1}" ></h:outputText>
<f:convertDateTime pattern="mm/dd/yyyy"/>
</h:column>
from1 is a calendar data type (without adding converter it is showing calendar data fine)
(jl: disabled smilies)
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14571
|
|
I think I see your problem, but if you use the "Code" button to wrap code tags around your XML, it won't get mangled.
Here is the proper use of the converter:
|
 |
nikhil katoch
Greenhorn
Joined: Jun 09, 2012
Posts: 10
|
|
I did it and got
java.lang.IllegalArgumentException: Cannot format given Object as a Date
(is it because object is calendar???)
(thanks for trying Tim I really appreciate your efforts!!)
|
 |
Junilu Lacar
Bartender
Joined: Feb 26, 2001
Posts: 4134
|
|
|
then try row.from1.date
|
Junilu - [How to Ask Questions] [How to Answer Questions] [MiH]
|
 |
nikhil katoch
Greenhorn
Joined: Jun 09, 2012
Posts: 10
|
|
i did it and got
org.apache.jasper.el.JspPropertyNotFoundException: /issue1.jsp(50,4) '#{row.from1.date}' Property 'date' not found on type java.util.GregorianCalendar
|
 |
Junilu Lacar
Bartender
Joined: Feb 26, 2001
Posts: 4134
|
|
I'm sorry you couldn't find the right method to call on the java.util.Calendar, Nikhil. I was trying to get you to ShowSomeEffort by finding the JavaDocs that actually had the answer. (hint hint)
|
 |
nikhil katoch
Greenhorn
Joined: Jun 09, 2012
Posts: 10
|
|
I will try JavaDocs for sure.(I also tried to use only date object in whole program (to eradicate calendar issue) but still I was getting error)
when I used
the codes were not working as expected (you know that for sure!!! )but when I used
I got the desired result (but still unable to understand why only by shifting </h utputText> to next line made the program work???)
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14571
|
|
nikhil katoch wrote:
I got the desired result (but still unable to understand why only by shifting </h  utputText> to next line made the program work???)
I doubt that it did. Though it's possible that updating the View definition one last time pushed out some stale code or data.
|
 |
 |
|
|
subject: unable to type case
|
|
|