Hello,
I am trying to create a sublass of ListGridRecord to be used in ListGrid which automatically makes the ListGridRecord row turn red once a certain attribute is set to true, and turn back to white once it is set to white. The class I have created for this looks like this:
Where WcuIncompatibleReasonTypes is a simple enum.
The problem I am facing with this is that if I populate a RecordList using my new class, as such:
And then try to get one of these records and cast them to my class I always get ClassCastException:
*13:53:07.319:MUP5:WARN:Log:java.lang.ClassCastException
at Throwable_1_g$(FastePortal-0.js@8:5765)
at Exception_1_g$(FastePortal-0.js@18:6013)
at RuntimeException_1_g$(FastePortal-0.js@18:6060)
at ClassCastException_1_g$(FastePortal-0.js@25:23534)
at checkCriticalType_0_g$(FastePortal-0.js@21:307199)
at checkType_0_g$(FastePortal-0.js@5:307406)
at castTo_0_g$(FastePortal-0.js@3:647)
at validateSelectedWCUs_3_g$(FastePortal-0.js@12:445361)
at onChanged_142_g$(FastePortal-0.js@24:445520)
at dispatch_362_g$(FastePortal-0.js@16:236194)
at dispatch_361_g$(FastePortal-0.js@8:236190)
at dispatch_0_g$(FastePortal-0.js@8:37786)
at dispatchEvent_2_g$(FastePortal-0.js@14:39425)
at doFire_0_g$(FastePortal-0.js@9:39523)
at fireEvent_1_g$(FastePortal-0.js@8:39596)
at fireEvent_0_g$(FastePortal-0.js@24:39374)
at fireEvent_10_g$(FastePortal-0.js@23:94535)
at <anonymous>(FastePortal-0.js@16:221777)
at apply_43_g$(FastePortal-0.js@28:29667)
at entry0_0_g$(FastePortal-0.js@16:29723)
at changed(FastePortal-0.js@14:29703)
at isc_FormItem_handleChanged(http://localhost:8080/wice/FastePort...rms.js@22:1100)
at isc_FormItem_storeValue(http://localhost:8080/wice/FastePort...rms.js@23:1099)
at isc_FormItem__updateValue(http://localhost:8080/wice/FastePort...rms.js@68:1096)
at isc_CycleItem_advanceValue(http://localhost:8080/wice/FastePort...ms.js@220:2154)
at isc_CycleItem_handleClick(http://localhost:8080/wice/FastePort...ms.js@192:2148)
at isc_DynamicForm_bubbleItemHandler(http://localhost:8080/wice/FastePort...orms.js@10:553)
at isc_DynamicForm_handleItemClick(http://localhost:8080/wice/FastePort...orms.js@89:559)
at isc_DynamicForm_handleClick(http://localhost:8080/wice/FastePort...rms.js@508:554)
at isc_c_EventHandler_bubbleEvent(http://localhost:8080/wice/FastePort...ore.js@89:1730)
at isc_c_EventHandler_handleClick(http://localhost:8080/wice/FastePort...ore.js@50:1588)
at isc_c_EventHandler__handleMouseUp(http://localhost:8080/wice/FastePort...ore.js@11:1573)
at isc_c_EventHandler_handleMouseUp(http://localhost:8080/wice/FastePort...ore.js@57:1564)
at isc_c_EventHandler_dispatch(http://localhost:8080/wice/FastePort...re.js@108:1808)
at eval(eval at isc__makeFunction (http://localhost:8080/wice/FastePort...Core.js@122:79)
Achieved by this code:
So for some reason, the ListGridRecords I get out are not actually ListGridRecordWithAutoBaseStyle. Does anyone have anyone know why and if it can be solved?
It appears that when I create the RecordList using objects of ListGridRecordWithAutoBaseStyle, they automatically become their parent class again, ListGridRecord. This can be tested by this simple code:
This always returns false.
I am trying to create a sublass of ListGridRecord to be used in ListGrid which automatically makes the ListGridRecord row turn red once a certain attribute is set to true, and turn back to white once it is set to white. The class I have created for this looks like this:
Code:
public class ListGridRecordWithAutoBaseStyle extends ListGridRecord { public ListGridRecordWithAutoBaseStyle(Record record) { super(record); } /* (non-Javadoc) * [USER="61157"]see[/USER] com.smartgwt.client.core.DataClass#setAttribute(java.lang.String, boolean) * Overriden to always set the base style to "assignment-Error" if the ListGridRecord contains a * WcuIncomaptibleReasonTypes in its attribute and is set to true. If the ListGridRecord does * not contain a WcuIncompatibleReasonTypes that is set to true, the baseStyle i set to "cell". */ @Override public void setAttribute(String property, boolean value) { super.setAttribute(property, value); if(isWcuInIncompatibleList(this)) super.set_baseStyle("assignment-Error"); //Makes the row red else super.set_baseStyle("cell"); // Makes the row white } private boolean isWcuInIncompatibleList(ListGridRecord rec){ for(WcuIncompatibleReasonTypes wirt: WcuIncompatibleReasonTypes.values()) if(rec.getAttributeAsBoolean(wirt.name())) return true; return false; } }
The problem I am facing with this is that if I populate a RecordList using my new class, as such:
Code:
public void addRecords(RecordList records) { RecordList tempRecordList = new RecordList(); for(Record record : records.getRange(0, records.getLength())) { tempRecordList.add(new ListGridRecordWithAutoBaseStyle(record)); } resources.setData(tempRecordList); }
*13:53:07.319:MUP5:WARN:Log:java.lang.ClassCastException
at Throwable_1_g$(FastePortal-0.js@8:5765)
at Exception_1_g$(FastePortal-0.js@18:6013)
at RuntimeException_1_g$(FastePortal-0.js@18:6060)
at ClassCastException_1_g$(FastePortal-0.js@25:23534)
at checkCriticalType_0_g$(FastePortal-0.js@21:307199)
at checkType_0_g$(FastePortal-0.js@5:307406)
at castTo_0_g$(FastePortal-0.js@3:647)
at validateSelectedWCUs_3_g$(FastePortal-0.js@12:445361)
at onChanged_142_g$(FastePortal-0.js@24:445520)
at dispatch_362_g$(FastePortal-0.js@16:236194)
at dispatch_361_g$(FastePortal-0.js@8:236190)
at dispatch_0_g$(FastePortal-0.js@8:37786)
at dispatchEvent_2_g$(FastePortal-0.js@14:39425)
at doFire_0_g$(FastePortal-0.js@9:39523)
at fireEvent_1_g$(FastePortal-0.js@8:39596)
at fireEvent_0_g$(FastePortal-0.js@24:39374)
at fireEvent_10_g$(FastePortal-0.js@23:94535)
at <anonymous>(FastePortal-0.js@16:221777)
at apply_43_g$(FastePortal-0.js@28:29667)
at entry0_0_g$(FastePortal-0.js@16:29723)
at changed(FastePortal-0.js@14:29703)
at isc_FormItem_handleChanged(http://localhost:8080/wice/FastePort...rms.js@22:1100)
at isc_FormItem_storeValue(http://localhost:8080/wice/FastePort...rms.js@23:1099)
at isc_FormItem__updateValue(http://localhost:8080/wice/FastePort...rms.js@68:1096)
at isc_CycleItem_advanceValue(http://localhost:8080/wice/FastePort...ms.js@220:2154)
at isc_CycleItem_handleClick(http://localhost:8080/wice/FastePort...ms.js@192:2148)
at isc_DynamicForm_bubbleItemHandler(http://localhost:8080/wice/FastePort...orms.js@10:553)
at isc_DynamicForm_handleItemClick(http://localhost:8080/wice/FastePort...orms.js@89:559)
at isc_DynamicForm_handleClick(http://localhost:8080/wice/FastePort...rms.js@508:554)
at isc_c_EventHandler_bubbleEvent(http://localhost:8080/wice/FastePort...ore.js@89:1730)
at isc_c_EventHandler_handleClick(http://localhost:8080/wice/FastePort...ore.js@50:1588)
at isc_c_EventHandler__handleMouseUp(http://localhost:8080/wice/FastePort...ore.js@11:1573)
at isc_c_EventHandler_handleMouseUp(http://localhost:8080/wice/FastePort...ore.js@57:1564)
at isc_c_EventHandler_dispatch(http://localhost:8080/wice/FastePort...re.js@108:1808)
at eval(eval at isc__makeFunction (http://localhost:8080/wice/FastePort...Core.js@122:79)
Achieved by this code:
Code:
public ListGridRecordWithAutoBaseStyle[] getSelectedRecords() { return (ListGridRecordWithAutoBaseStyle[]) resources.getRecords(); }
It appears that when I create the RecordList using objects of ListGridRecordWithAutoBaseStyle, they automatically become their parent class again, ListGridRecord. This can be tested by this simple code:
Code:
public void addRecords(RecordList records) { RecordList tempRecordList = new RecordList(); for(Record record : records.getRange(0, records.getLength())) { ListGridRecordWithAutoBaseStyle a = new ListGridRecordWithAutoBaseStyle(record); tempRecordList.add(new ListGridRecordWithAutoBaseStyle(record)); } if(tempRecordList.get(0) instanceof ListGridRecordWithAutoBaseStyle) GWT.log("true"); else GWT.log("false"); }
Comment