Hi Chris,
thank you for the solution, using a new serializer did it.
For your information and future reference:
My sample bxml contained a pushbutton and a label, pressing the button
would update the label.
If I load two of these panels I now have two buttons and two labels. If i do
serializer.getNamespace().clear();
and press a button then both labels in both panels would be updated
(which is incorrect) while creating a new instance of the serializer
makes it behave correctly.
Thanks,
Joe
Chris Bartlett wrote:
Joe,
I'll try to run your example shortly, but in the mean time...
Have you tried using a new BXMLSerializer instance to load each new BXML
file?
serializer = new BXMLSerializer();
Or to clear the namespace of the BXMLSerializer between uses?
serializer.getNamespace().clear();
Chris
On 19 April 2011 16:36, Joe Minichino - TechFort <[email protected]
<mailto:[email protected]>> wrote:
Hi Chris,
thank you for your time and the quick answer.
Here's a very basic example, a window containing a button which is
used to load more bxml files.
First time i press the button I get the new panel added to the ui no
problem, the second time i get the exception under the class code
(complaining that the bxml:id testEventBtn is already in use).
joe
// Bindable window...
public class BindableWindow extends Window implements Bindable {
BXMLSerializer serializer = new BXMLSerializer();
@BXML(id="mainPane") BoxPane mainPane = null;
@BXML PushButton testButton = null;
@Override
public void initialize(Map<String, Object> arg0,
URL arg1, Resources arg2) {
testButton.getButtonPressListeners()
.add(new ButtonPressListener() {
@Override
public void buttonPressed(Button arg0) {
loadApp();
}
});
}
public void loadApp(){
BoxPane boxpane;
try {
boxpane = (BoxPane) serializer.readObject(
getClass().getResource("sample.bxml") );
mainPane.add(boxpane);
} catch (IOException e) {
....
}
}
}
//sample.xml
<BoxPane
xmlns="org.apache.pivot.wtk"
xmlns:bxml="http://pivot.apache.org/bxml"
>
<PusButton bxml:id="testEventBtn" buttonData="click me" />
</BoxPane>
The exception thrown:
An error occurred at line number 20 in file .../sample.bxml:
org.apache.pivot.serialization.SerializationException: ID
testEventBtn is already in use.
at
org.apache.pivot.beans.BXMLSerializer.processAttributes(BXMLSerializer.java:934)
at
org.apache.pivot.beans.BXMLSerializer.processStartElement(BXMLSerializer.java:801)
at
org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:435)
at
org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:614)
at
org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:587)
at
com.techfort.appwall.ui.BindableWindow.loadApp(BindableWindow.java:54)
at
com.techfort.appwall.ui.BindableWindow$1.buttonPressed(BindableWindow.java:39)
at
org.apache.pivot.wtk.Button$ButtonPressListenerList.buttonPressed(Button.java:194)
at org.apache.pivot.wtk.Button.press(Button.java:412)
at org.apache.pivot.wtk.PushButton.press(PushButton.java:70)
at
org.apache.pivot.wtk.skin.PushButtonSkin.mouseClick(PushButtonSkin.java:77)
at
org.apache.pivot.wtk.skin.terra.TerraPushButtonSkin.mouseClick(TerraPushButtonSkin.java:586)
at
org.apache.pivot.wtk.Component$ComponentMouseButtonListenerList.mouseClick(Component.java:483)
at org.apache.pivot.wtk.Component.mouseClick(Component.java:2777)
at org.apache.pivot.wtk.Container.mouseUp(Container.java:774)
at org.apache.pivot.wtk.Container.mouseUp(Container.java:759)
at org.apache.pivot.wtk.Container.mouseUp(Container.java:759)
at
org.apache.pivot.wtk.ApplicationContext$DisplayHost.processMouseEvent(ApplicationContext.java:914)
at java.awt.Component.processEvent(Component.java:6139)
at
org.apache.pivot.wtk.ApplicationContext$DisplayHost.processEvent(ApplicationContext.java:709)
at java.awt.Component.dispatchEventImpl(Component.java:4736)
at java.awt.Component.dispatchEvent(Component.java:4566)
at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4621)
at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)
at
java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
at java.awt.Container.dispatchEventImpl(Container.java:2129)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4566)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:680)
at java.awt.EventQueue.access$000(EventQueue.java:86)
at java.awt.EventQueue$1.run(EventQueue.java:639)
at java.awt.EventQueue$1.run(EventQueue.java:637)
at java.security.AccessController.doPrivileged(Native Method)
at
java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at
java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:653)
at java.awt.EventQueue$2.run(EventQueue.java:651)
at java.security.AccessController.doPrivileged(Native Method)
at
java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:650)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Chris Bartlett wrote:
Joe,
Could you elaborate a little please? (Or better yet, provide a
small example app - but hold off on that for now unless you can
put one together without too much effort)
Is an Exception thrown when you load the 'nested panel' BXML
file using BXMLSerializer, or possibly when you try to add the
serialized Component graph to the your 'main UI panel', or
somewhere else again?
http://pivot.apache.org/tutorials/bxml-primer.html
BXMLSerializer handles a similar situation internally when
<bxml:include inline="false"> is used to include additional BXML
files into a parent BXML file. This ensures that each included
BXML file has its own namespace and therefore avoids clashes.
This allows the exact same BXML file to be included multiple
times into the same parent BXML file without namespace collisions.
I'm pretty sure there will be a way around this, but I'm not at
a dev machine, so can't investigate right now.
Chris
On 19 April 2011 15:21, Joe Minichino - TechFort
<[email protected] <mailto:[email protected]>
<mailto:[email protected] <mailto:[email protected]>>> wrote:
Hi,
I am new to Pivot, but I am really impressed by it, well done.
I have a main UI with a panel that hosts other panels. These
nested
panels are simply bxml files dynmically loaded at runtime through
user input and added to the main view (say a user enters the
name of
the bxml file to load and that bxml gets added to the view).
Problem is that if I try to load a bxml file that contains an id
that's already in use the new bxml file won't load.
I can see how this feature could be by design so my question
is if
there is anyway to enforce bxml:id scoping so that I won't
have to
deal with these type of id conflicts or keep track of the id's
already in use?
Thanks
Joe