Author |
Message |
24/07/2008 11:29:59
|
wocher
Power User
Joined: 14/04/2008 13:10:19
Messages: 49
Location: Ravensburg
Offline
|
Hi Björn,
my problem is by the AbstractBeanWrapper.
This field will return a string not a date object.
By the way in direkt way in a methode setSomeThing( java.util.Date date )
a date object will set.
in my AbstractBeanWrapper is the put ( String property, Object value )
in this way a string with the date will get to the class.
Can you fix this? Or must i convert the text string to a Date Object?
to the .jsf site the AbstractBeanWrapper gives a Date Object.
Greet Wocher
|
„Ein Haus ohne Bücher ist arm, auch wenn schöne Teppiche seinen Boden und kostbare Tapeten und Bilder die Wände bedecken.“
Hermann Hesse, Dichter, Schriftsteller und Maler * 02. 07. 1877 - Calw † 09. 08. 1962 - Montagnola, Schweiz
Rainer Wocher Quentia Development GmbH (Sotware Developer) |
|
|
24/07/2008 16:40:11
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5520
Offline
|
Hi,
well "fixing" is not the right word, because this is the value binding which is done by JSF. We ask JSF for the result type and with a hashtable JSF cannot really tell.
But what we can do is to get in between: if the data is coming from a component that is data-type aware (e.g. CALENDARFIELD and FORMATTEDFIELD) then we first try to find the most specific data type (e.g. Date) and then switch over to String.
Should be "in" next Monday.
Pls. tell if this does not solve your problem...
Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
29/07/2008 11:41:07
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5520
Offline
|
...with today's update there is an update, as you (and others) requested. Please check the updated docu coming with the update, chapter "Working with Managed Beans", there is a chapter talking about the data type issue.
Thanks for your input,
Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
11/11/2008 14:06:21
|
fmueller
Active
Joined: 15/09/2008 11:29:45
Messages: 16
Offline
|
Hello Mr. Mueller,
looks like t:calendarfiled is back to returning Strings instead of Dates, thus messing up any setters that expect Dates.
=> java.lang.IllegalArgumentException: argument type mismatch
|
|
|
11/11/2008 14:28:41
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5520
Offline
|
...hmm. What's the concrete scenario?
The value that is passed is either taken from the value binding (then it is the type of the bound property) or in case you use dynamic binding (hash maps) then each component has a preferred data type, which is Date in the case of CalendarField.
I double checked the dynamic scenario - "Date" is returened...
Pls give me some more info about how the property that is boudn behind the value of the calendarfield is accessed. Thanks!
Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
11/11/2008 14:53:45
|
wocher
Power User
Joined: 14/04/2008 13:10:19
Messages: 49
Location: Ravensburg
Offline
|
wocher wrote:
Hi Björn,
my problem is by the AbstractBeanWrapper.
This field will return a string not a date object.
By the way in direkt way in a methode setSomeThing( java.util.Date date )
a date object will set.
in my AbstractBeanWrapper is the put ( String property, Object value )
in this way a string with the date will get to the class.
Can you fix this? Or must i convert the text string to a Date Object?
to the .jsf site the AbstractBeanWrapper gives a Date Object.
Greet Wocher
the same problem...
i type the format value to date and the put operation of this property was also a string not a date.
AbstractBeanWrapper<BT> extends HashMap<String, Object> {
....
put(String key, Object value) {
...
}
|
„Ein Haus ohne Bücher ist arm, auch wenn schöne Teppiche seinen Boden und kostbare Tapeten und Bilder die Wände bedecken.“
Hermann Hesse, Dichter, Schriftsteller und Maler * 02. 07. 1877 - Calw † 09. 08. 1962 - Montagnola, Schweiz
Rainer Wocher Quentia Development GmbH (Sotware Developer) |
|
|
11/11/2008 15:29:56
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5520
Offline
|
Hi,
this is my code:
Code:
package workplace;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.event.ActionEvent;
import org.eclnt.editor.annotations.CCGenClass;
import org.eclnt.jsfserver.defaultscreens.Statusbar;
@CCGenClass (expressionBase="#{wp.DemoAaaaa}")
public class DemoAaaaa implements Serializable
{
Map<String,Object> m_props = new HashMap<String, Object>();
public Map<String,Object> getProps()
{
return m_props;
}
public void onOutputProps(ActionEvent event)
{
if (m_props.containsKey("aaaaa"))
Statusbar.outputMessage(m_props.get("aaaaa").getClass().getName());
}
}
This is my layout:
Code:
<t:row id="g_4" >
<t:calendarfield id="g_5" value="#{wp.DemoAaaaa.props.aaaaa}" width="200" format="datetime"/>
</t:row>
In my system the output in the statusbar is "java.util.Date".
What's differnent compared to your scenario?
Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
11/11/2008 17:20:10
|
fmueller
Active
Joined: 15/09/2008 11:29:45
Messages: 16
Offline
|
not much different, except we're using a macro:
<t:calendarfield id="g_87" attributemacro="wb(myDispatchedBean, myBeanWrapper, myDateVar)" flush="true" format="date" timezone="GMT" width="120" />
..
however, discarding the macro and using something like value="#{d.myDispatchedBean.myBeanWrapper.myDateVar}" has no effect and still results in an argument type mismatch.
We watched the overriden "put"-Method of our AbstractBeanWrapper closely and saw a String passed as value-Object. Shouldn't that be a Date?
|
|
|
11/11/2008 17:32:50
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5520
Offline
|
Hi,
what we do:
(1) we check the value binding (that's the JSF object behind a value-expression); this one provides for a getType(). IF this returns a type then we take this type. Background: you can have a class with String set/getXYZ(). In this case we convert the valuem, so that the application has no effort.
(2) if the value binding tells us "no type available" (as with dynamic mapping to hash tables) then each component has a preferred data type. In the CALENDARFIELD this is Date.
So, my expectation would be that you are case (2), but for some reason the value binding seems to pass us back a String type, so that we do not askt for the component's preferred type.
We'll do some extended testing here + follow up...
Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
26/04/2009 12:37:36
|
mreich
Power User
Joined: 30/01/2009 08:34:23
Messages: 744
Offline
|
Hi,
I'm facing the same problems, I also use a <String, Object> Map for value binding, I but in a Timestamp object and when retrieving the entered value I got a String back.
Is there a simple workaround? I don't want to start converting with simple date format parsing, etc ..
regards
Markus
|
|
|
26/04/2009 16:46:42
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5520
Offline
|
Hi,
I wrote this little demo program:
Code:
Map<String,Object> m_data = new HashMap<String,Object>();
public Map<String,Object> getData() { return m_data; }
public void onOutputMapData(ActionEvent event)
{
System.out.println("Map Dump...");
System.out.println("Map Dump...");
System.out.println("Map Dump...");
for (String key: m_data.keySet())
{
Object value = m_data.get(key);
if (value == null)
continue;
System.out.println("KEY: " + key +", VALUE: " + value.toString() + "/" + value.getClass().getName());
}
System.out.println("Map Dump...");
System.out.println("Map Dump...");
System.out.println("Map Dump...");
}
and the corresponding page:
Code:
<f:view>
<h:form>
<f:subview id="ztest_dateg_sv">
<t:rowtitlebar id="g_1" />
<t:rowheader id="g_2">
<t:button id="g_3" actionListener="#{wp.DemoAaaaa.onOutputMapData}"
text="Output Map Data" />
</t:rowheader>
<t:rowbodypane id="g_4">
<t:row id="g_5">
<t:calendarfield id="g_6" format="datetime"
value="#{wp.DemoAaaaa.data.date}" width="200" />
</t:row>
</t:rowbodypane>
<t:rowstatusbar id="g_7" />
<t:pageaddons id="g_pa" />
</f:subview>
</h:form>
</f:view>
When pressing outputData I get:
Code:
Map Dump...
Map Dump...
Map Dump...
KEY: date, VALUE: Fri Apr 10 16:46:06 CEST 2009/java.util.Date
Map Dump...
Map Dump...
Map Dump...
...a perfect "Date"....
Is it possible that the value in your hash map is preset with a String already? In this case JSF says "keep with what's available".
Are you using a different component. maybe? I tested with FORMATTEDFIELD as well, same result as above.
Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
26/04/2009 18:59:00
|
mreich
Power User
Joined: 30/01/2009 08:34:23
Messages: 744
Offline
|
Hi Björn,
again thanx for your quick response!
In my case the root of evil was the the type Timestamp, although this class is a subclass of Date. So I tried to cast from Timestamp to Date and put this into my value map. In the map the date field was still a Timestamp Class, the calendarfield shows the right date, but when changing the value, it returned a String and not a Timestamp or Date class!
I now create a new Date field and set this field with the values from the Timestamp field (Date date = new Date(timestamp.getTime());)
Should I put this into the Snippet zone, maybe others also work with Hibernate/mySQL which usually use TimeStamp type for date handling?
regards
Markus
|
|
|
26/04/2009 19:27:04
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5520
Offline
|
....yes, of course!
The snippet zone is waiting for its first real posting anyway ;-)
Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
|