You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Sandro Martini <sa...@gmail.com> on 2012/08/07 14:12:07 UTC

Re: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Hi and welcome to Pivot,
note that you should subscribe to our mailing lists (some info here:
http://pivot.apache.org/lists.html ) or at least to our users list,
otherwise your posts here won't be accepted (and not visible to users).

Anyway, as seen here:
http://pivot.apache.org/tutorials/bxml-primer.html

An extract:
BXML includes are often used for partitioning content into manageable pieces
(for example, when working on large applications or with multiple
developers, or when defining reusable content templates). By default, each
include is assigned its own variable namespace to avoid naming collisions
with ancestor documents; however, this behavior can be overridden by adding
an "inline" attribute with a value of "true" to the <bxml:include> tag. 

So, in short, try to add inline="true" to your include.
In Pivot sources you can find some sample for this in:
tests/ ... /inline_test.bxml
tutorials/ ... / menus.bxml

This should be enough, keep us updated.

Bye,
Sandro




--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/in-java-how-can-i-reference-the-instance-define-in-a-nested-bxml-s-bxml-id-tp4022008p4022010.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Posted by "Mark R. Chambers" <ma...@mrchambers.org>.
Hi All,

Thought this might be useful to somebody.  This allows you to just use names
in you bxml, so that you can reuse components names under a heirachy.
(Everything under the namespace id you get still needs to be unique... but
better than not be able to do it...)

I wrote a simple way to get a named component. It will go through all of a
containers children and find the first occurrence of that named component...
 (not efficient... and should really build a hashmap of all components and
then just do a lookup later.....(will do that later...) 

USAGE EXAMPLE:
for(int i=0; i<mTabCount; i++)
{
	mBoxPane[i] = (BoxPane)namespace.get("tab" + i);
            	mCardPane[i] = (CardPane)GetFirstChildWithName(mBoxPane[i],
"cardpane");
}

THE CODE: (Just put these methods somewhere...)
    private Component GetFirstChildWithName(Container vContainer, String
vChildName) {
        if (vChildName == null) {
            throw new IllegalArgumentException();
        }
        Component vComponent =
GetFirstChildWithNameRecursive(vContainer,vChildName,null);
        if(vComponent==null){
            mLog.warning("Component With Name("+vChildName+")Could not be
found in Container("+vContainer.getName()+")");
        }
        return vComponent;
    }

    public Component GetFirstChildWithNameRecursive (Container vContainer,
String vChildName, Component vFoundComponent){
        // What data are you looking for again?
        if(vFoundComponent!=null) return vFoundComponent;
        if(vContainer==null) return null;
        for (Component vComponent : vContainer) {
            //Some debug stuff if you want it;]
            //mLog.info("ComponentName("+vComponent.getName()+").");
            if (vChildName.equals(vComponent.getName())) {
                return vComponent;
            }else{
                try{
                    Container vTempContainer = (Container)vComponent;
                    if(vTempContainer!=null){
                        Component vNewComponent =
GetFirstChildWithNameRecursive (vTempContainer,vChildName, null);
                        if (vChildName.equals(vNewComponent.getName())) {
                            return vNewComponent;
                        }
                    }
                }catch(Exception e)
                {
                    //e.printStackTrace();
                }
            }
        }

        return null;
    }

Regards,
Mark.
-----Original Message-----
From: Mark R. Chambers [mailto:mark@mrchambers.org] 
Sent: Thursday, 30 January 2014 8:46 AM
To: user@pivot.apache.org; karel.hubl@gemsystem.cz
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Karel,

Thanks for your feedback.  Appreciate the effort and thanks for the
Examples.
Yeah I had a feeling that getnamed did not traverse, and is good to know
that the window cannot have multiple children.
Also I am currently already using some custom components, but have not been
using the containers, since I want the GUI defined in XML... and putting it
into a class kind of defeats the purpose of using bxml.  If the Container
could read in a BXML file then this would resolve this;] Also using
getNamedComponent if Hierarchical means that I lock in the formatting of the
GUI in code, which once again defeats the purpose off using bxml...
Unless I create a component traversal class, that automatically goes through
all children of a class to find the named component...(Might do this, should
be fairly easy and only ever use the first component to begin the search.
This would mean that I could solve all bxml reusability problems.

SUMMARY:
I will create a component traversal lookup method and give all components in
the bxml files unique names using script variable assignment to name="" in
the bxml.  This should allow me to completely separate the GUI from the
backend... Then in documentation I just need to define the required
component names and class types and the GUI can then be completely
redesigned in just XML and not have any impact on the backend.

Regards,
Mark.

-----Original Message-----
From: Karel Hübl [mailto:karel.hubl@gemsystem.cz]
Sent: Wednesday, 29 January 2014 5:29 PM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Mark,

I checked your code and found following problems:

1) Your MyView class is window. Window may not have multiple child
components. So I moved your subviews to BoxPane, which is only child of your
main Window.
2) Your subviews were also MyView instances - so you build some kind of
recursion which I think was not your intent. So I changed your subviews to
Borders.
3) The getNamedComponent does not traverse the whole component hierarchy. It
tries to look up only for child component with specified name (not childeren
of child components). So you need to split the lookup into multiple
getNamedComponent calls:
	...
	Container boxPane=(Container)getNamedComponent("boxPane");
	Container subview1=(Container)boxPane.getNamedComponent("subview1");
	Form myForm=(Form)subview1.getNamedComponent("loginForm");
	...

Anyway the fixed code is not very transparent in my opinion. The
bxml:include is suitable to partition large content into multiple parts for
better maintability. I would consider building reusable components using
java classes extending standard pivot containers. 

Find fixed code in attachment. I added myComponent package, where You can
see sample impementation of reusable component as I proposed...

Regards Karel



-----Original Message-----
From: Mark R. Chambers [mailto:mark@mrchambers.org]
Sent: Monday, January 27, 2014 10:04 PM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Karel,

I have tried it out, but am having trouble passing a variable into it.
I have modified your example here, to just add and additional username and
password field below the previous one.
In this example the username and login is the generic component that I want
to repeat and get access to...
It seems to work for the first name set, but not the second one... might
need to set the javascript higher up... maybe declaring the var twice causes
a problem?

Any ideas? 
Regards,
Mark.

-----Original Message-----
From: Roger L. Whitcomb [mailto:Roger.Whitcomb@actian.com]
Sent: Friday, 24 January 2014 3:40 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

So, after digging into this some more, I begin to see what you mean.  If you
don't use "inline='true'" on your "bxml:include" then there is no way
(directly) to get access to the included file's serializer, and thus its
namespace.  If you use "inline" (of course) then you have the possibility of
name collisions.

One possible solution to this is to use a custom subclass of BXMLSerializer
(that you would have to register using
BXMLSerializer.getMimeTypes().put("bxml", your new Serializer class)) that
would do something different with the namespace map.  The difficulty would
be associating the namespace of the included file with the main file's
namespace, since there is no connection (currently).

It definitely does seem like we *should* be able to deal with this situation
more gracefully, but I'm at somewhat of a loss right now what to suggest.
Perhaps we could make a change, and pass some more information to an
"include"d serializer that would tell it to put its variables into the
parent's namespace as something like the bxml:id of the include element
followed by ":" and the id.  Then for multiple levels of nesting you would
get "a:b:c", and etc.  How that would work with the variable bindings,
(i.e., using "serializer.bind(...)") I don't know.

Anyone else have thoughts?  *Perhaps* there is some way, as Karel is
suggesting, of using namespace binding, but I'm not seeing that either.  Of
course, making a Pivot change like this isn't likely to help with your
deadline.

So, I guess my best suggestion at this point is to make wise choices about
how you split up your BXML files, and how the "include" structure works, so
that you don't have to do cross-file referencing.  And/or make judicious use
of "inline='true'" to put the included variables into the main file's
namespace.

Anybody else see something I'm not seeing?

Thanks,
~Roger

-----Original Message-----
From: Roger L. Whitcomb [mailto:Roger.Whitcomb@actian.com]
Sent: Thursday, January 23, 2014 10:08 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Mark,
	I assume you've read through the BXML Primer here:
http://pivot.apache.org/tutorials/bxml-primer.html  It describes how
namespaces work and the "bxml:include" semantics (including the "inline"
attribute).  But, I think that the default behavior of making a separate
namespace for each included BXML file would satisfy your requirements,
unless I don't understand what you're trying to do.

Let us know,
~Roger

-----Original Message-----
From: Ripgiblet [mailto:mark@mrchambers.org]
Sent: Thursday, January 23, 2014 3:12 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Karel,

Thanks for the response, seemed like what I needed, but I cant seem to get
it too work...
Bit of a deadline on this, later I will try compiling your code and check it
works... I must be missing something...

regards,
Mark.



--
View this message in context:
http://apache-pivot-users.399431.n3.nabble.com/in-java-how-can-i-reference-t
he-instance-define-in-a-nested-bxml-s-bxml-id-tp4022008p4022838.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.





RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Posted by "Mark R. Chambers" <ma...@mrchambers.org>.
Hi Karel,

Thanks for your feedback.  Appreciate the effort and thanks for the
Examples.
Yeah I had a feeling that getnamed did not traverse, and is good to know
that the window cannot have multiple children.
Also I am currently already using some custom components, but have not been
using the containers, since I want the GUI defined in XML... and putting it
into a class kind of defeats the purpose of using bxml.  If the Container
could read in a BXML file then this would resolve this;]
Also using getNamedComponent if Hierarchical means that I lock in the
formatting of the GUI in code, which once again defeats the purpose off
using bxml...
Unless I create a component traversal class, that automatically goes through
all children of a class to find the named component...(Might do this, should
be fairly easy and only ever use the first component to begin the search.
This would mean that I could solve all bxml reusability problems.

SUMMARY:
I will create a component traversal lookup method and give all components in
the bxml files unique names using script variable assignment to name="" in
the bxml.  This should allow me to completely separate the GUI from the
backend... Then in documentation I just need to define the required
component names and class types and the GUI can then be completely
redesigned in just XML and not have any impact on the backend.

Regards,
Mark.

-----Original Message-----
From: Karel Hübl [mailto:karel.hubl@gemsystem.cz] 
Sent: Wednesday, 29 January 2014 5:29 PM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Mark,

I checked your code and found following problems:

1) Your MyView class is window. Window may not have multiple child
components. So I moved your subviews to BoxPane, which is only child of your
main Window.
2) Your subviews were also MyView instances - so you build some kind of
recursion which I think was not your intent. So I changed your subviews to
Borders.
3) The getNamedComponent does not traverse the whole component hierarchy. It
tries to look up only for child component with specified name (not childeren
of child components). So you need to split the lookup into multiple
getNamedComponent calls:
	...
	Container boxPane=(Container)getNamedComponent("boxPane");
	Container subview1=(Container)boxPane.getNamedComponent("subview1");
	Form myForm=(Form)subview1.getNamedComponent("loginForm");
	...

Anyway the fixed code is not very transparent in my opinion. The
bxml:include is suitable to partition large content into multiple parts for
better maintability. I would consider building reusable components using
java classes extending standard pivot containers. 

Find fixed code in attachment. I added myComponent package, where You can
see sample impementation of reusable component as I proposed...

Regards Karel



-----Original Message-----
From: Mark R. Chambers [mailto:mark@mrchambers.org]
Sent: Monday, January 27, 2014 10:04 PM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Karel,

I have tried it out, but am having trouble passing a variable into it.
I have modified your example here, to just add and additional username and
password field below the previous one.
In this example the username and login is the generic component that I want
to repeat and get access to...
It seems to work for the first name set, but not the second one... might
need to set the javascript higher up... maybe declaring the var twice causes
a problem?

Any ideas? 
Regards,
Mark.

-----Original Message-----
From: Roger L. Whitcomb [mailto:Roger.Whitcomb@actian.com]
Sent: Friday, 24 January 2014 3:40 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

So, after digging into this some more, I begin to see what you mean.  If you
don't use "inline='true'" on your "bxml:include" then there is no way
(directly) to get access to the included file's serializer, and thus its
namespace.  If you use "inline" (of course) then you have the possibility of
name collisions.

One possible solution to this is to use a custom subclass of BXMLSerializer
(that you would have to register using
BXMLSerializer.getMimeTypes().put("bxml", your new Serializer class)) that
would do something different with the namespace map.  The difficulty would
be associating the namespace of the included file with the main file's
namespace, since there is no connection (currently).

It definitely does seem like we *should* be able to deal with this situation
more gracefully, but I'm at somewhat of a loss right now what to suggest.
Perhaps we could make a change, and pass some more information to an
"include"d serializer that would tell it to put its variables into the
parent's namespace as something like the bxml:id of the include element
followed by ":" and the id.  Then for multiple levels of nesting you would
get "a:b:c", and etc.  How that would work with the variable bindings,
(i.e., using "serializer.bind(...)") I don't know.

Anyone else have thoughts?  *Perhaps* there is some way, as Karel is
suggesting, of using namespace binding, but I'm not seeing that either.  Of
course, making a Pivot change like this isn't likely to help with your
deadline.

So, I guess my best suggestion at this point is to make wise choices about
how you split up your BXML files, and how the "include" structure works, so
that you don't have to do cross-file referencing.  And/or make judicious use
of "inline='true'" to put the included variables into the main file's
namespace.

Anybody else see something I'm not seeing?

Thanks,
~Roger

-----Original Message-----
From: Roger L. Whitcomb [mailto:Roger.Whitcomb@actian.com]
Sent: Thursday, January 23, 2014 10:08 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Mark,
	I assume you've read through the BXML Primer here:
http://pivot.apache.org/tutorials/bxml-primer.html  It describes how
namespaces work and the "bxml:include" semantics (including the "inline"
attribute).  But, I think that the default behavior of making a separate
namespace for each included BXML file would satisfy your requirements,
unless I don't understand what you're trying to do.

Let us know,
~Roger

-----Original Message-----
From: Ripgiblet [mailto:mark@mrchambers.org]
Sent: Thursday, January 23, 2014 3:12 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Karel,

Thanks for the response, seemed like what I needed, but I cant seem to get
it too work...
Bit of a deadline on this, later I will try compiling your code and check it
works... I must be missing something...

regards,
Mark.



--
View this message in context:
http://apache-pivot-users.399431.n3.nabble.com/in-java-how-can-i-reference-t
he-instance-define-in-a-nested-bxml-s-bxml-id-tp4022008p4022838.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.





RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Posted by Karel Hübl <ka...@gemsystem.cz>.
Hi Mark,

I checked your code and found following problems:

1) Your MyView class is window. Window may not have multiple child
components. So I moved your subviews to BoxPane, which is only child of your
main Window.
2) Your subviews were also MyView instances - so you build some kind of
recursion which I think was not your intent. So I changed your subviews to
Borders.
3) The getNamedComponent does not traverse the whole component hierarchy. It
tries to look up only for child component with specified name (not childeren
of child components). So you need to split the lookup into multiple
getNamedComponent calls:
	...
	Container boxPane=(Container)getNamedComponent("boxPane");
	Container subview1=(Container)boxPane.getNamedComponent("subview1");
	Form myForm=(Form)subview1.getNamedComponent("loginForm");
	...

Anyway the fixed code is not very transparent in my opinion. The
bxml:include is suitable to partition large content into multiple parts for
better maintability. I would consider building reusable components using
java classes extending standard pivot containers. 

Find fixed code in attachment. I added myComponent package, where You can
see sample impementation of reusable component as I proposed...

Regards Karel



-----Original Message-----
From: Mark R. Chambers [mailto:mark@mrchambers.org] 
Sent: Monday, January 27, 2014 10:04 PM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Karel,

I have tried it out, but am having trouble passing a variable into it.
I have modified your example here, to just add and additional username and
password field below the previous one.
In this example the username and login is the generic component that I want
to repeat and get access to...
It seems to work for the first name set, but not the second one... might
need to set the javascript higher up... maybe declaring the var twice causes
a problem?

Any ideas? 
Regards,
Mark.

-----Original Message-----
From: Roger L. Whitcomb [mailto:Roger.Whitcomb@actian.com]
Sent: Friday, 24 January 2014 3:40 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

So, after digging into this some more, I begin to see what you mean.  If you
don't use "inline='true'" on your "bxml:include" then there is no way
(directly) to get access to the included file's serializer, and thus its
namespace.  If you use "inline" (of course) then you have the possibility of
name collisions.

One possible solution to this is to use a custom subclass of BXMLSerializer
(that you would have to register using
BXMLSerializer.getMimeTypes().put("bxml", your new Serializer class)) that
would do something different with the namespace map.  The difficulty would
be associating the namespace of the included file with the main file's
namespace, since there is no connection (currently).

It definitely does seem like we *should* be able to deal with this situation
more gracefully, but I'm at somewhat of a loss right now what to suggest.
Perhaps we could make a change, and pass some more information to an
"include"d serializer that would tell it to put its variables into the
parent's namespace as something like the bxml:id of the include element
followed by ":" and the id.  Then for multiple levels of nesting you would
get "a:b:c", and etc.  How that would work with the variable bindings,
(i.e., using "serializer.bind(...)") I don't know.

Anyone else have thoughts?  *Perhaps* there is some way, as Karel is
suggesting, of using namespace binding, but I'm not seeing that either.  Of
course, making a Pivot change like this isn't likely to help with your
deadline.

So, I guess my best suggestion at this point is to make wise choices about
how you split up your BXML files, and how the "include" structure works, so
that you don't have to do cross-file referencing.  And/or make judicious use
of "inline='true'" to put the included variables into the main file's
namespace.

Anybody else see something I'm not seeing?

Thanks,
~Roger

-----Original Message-----
From: Roger L. Whitcomb [mailto:Roger.Whitcomb@actian.com]
Sent: Thursday, January 23, 2014 10:08 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Mark,
	I assume you've read through the BXML Primer here:
http://pivot.apache.org/tutorials/bxml-primer.html  It describes how
namespaces work and the "bxml:include" semantics (including the "inline"
attribute).  But, I think that the default behavior of making a separate
namespace for each included BXML file would satisfy your requirements,
unless I don't understand what you're trying to do.

Let us know,
~Roger

-----Original Message-----
From: Ripgiblet [mailto:mark@mrchambers.org]
Sent: Thursday, January 23, 2014 3:12 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Karel,

Thanks for the response, seemed like what I needed, but I cant seem to get
it too work...
Bit of a deadline on this, later I will try compiling your code and check it
works... I must be missing something...

regards,
Mark.



--
View this message in context:
http://apache-pivot-users.399431.n3.nabble.com/in-java-how-can-i-reference-t
he-instance-define-in-a-nested-bxml-s-bxml-id-tp4022008p4022838.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.




RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Posted by "Mark R. Chambers" <ma...@mrchambers.org>.
Hi Karel,

I have tried it out, but am having trouble passing a variable into it.
I have modified your example here, to just add and additional username and
password field below the previous one.
In this example the username and login is the generic component that I want
to repeat and get access to...
It seems to work for the first name set, but not the second one... might
need to set the javascript higher up... maybe declaring the var twice causes
a problem?

Any ideas? 
Regards,
Mark.

-----Original Message-----
From: Roger L. Whitcomb [mailto:Roger.Whitcomb@actian.com] 
Sent: Friday, 24 January 2014 3:40 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

So, after digging into this some more, I begin to see what you mean.  If you
don't use "inline='true'" on your "bxml:include" then there is no way
(directly) to get access to the included file's serializer, and thus its
namespace.  If you use "inline" (of course) then you have the possibility of
name collisions.

One possible solution to this is to use a custom subclass of BXMLSerializer
(that you would have to register using
BXMLSerializer.getMimeTypes().put("bxml", your new Serializer class)) that
would do something different with the namespace map.  The difficulty would
be associating the namespace of the included file with the main file's
namespace, since there is no connection (currently).

It definitely does seem like we *should* be able to deal with this situation
more gracefully, but I'm at somewhat of a loss right now what to suggest.
Perhaps we could make a change, and pass some more information to an
"include"d serializer that would tell it to put its variables into the
parent's namespace as something like the bxml:id of the include element
followed by ":" and the id.  Then for multiple levels of nesting you would
get "a:b:c", and etc.  How that would work with the variable bindings,
(i.e., using "serializer.bind(...)") I don't know.

Anyone else have thoughts?  *Perhaps* there is some way, as Karel is
suggesting, of using namespace binding, but I'm not seeing that either.  Of
course, making a Pivot change like this isn't likely to help with your
deadline.

So, I guess my best suggestion at this point is to make wise choices about
how you split up your BXML files, and how the "include" structure works, so
that you don't have to do cross-file referencing.  And/or make judicious use
of "inline='true'" to put the included variables into the main file's
namespace.

Anybody else see something I'm not seeing?

Thanks,
~Roger

-----Original Message-----
From: Roger L. Whitcomb [mailto:Roger.Whitcomb@actian.com] 
Sent: Thursday, January 23, 2014 10:08 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Mark,
	I assume you've read through the BXML Primer here:
http://pivot.apache.org/tutorials/bxml-primer.html  It describes how
namespaces work and the "bxml:include" semantics (including the "inline"
attribute).  But, I think that the default behavior of making a separate
namespace for each included BXML file would satisfy your requirements,
unless I don't understand what you're trying to do.

Let us know,
~Roger

-----Original Message-----
From: Ripgiblet [mailto:mark@mrchambers.org] 
Sent: Thursday, January 23, 2014 3:12 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Hi Karel,

Thanks for the response, seemed like what I needed, but I cant seem to get
it too work...
Bit of a deadline on this, later I will try compiling your code and check it
works... I must be missing something...

regards,
Mark.



--
View this message in context:
http://apache-pivot-users.399431.n3.nabble.com/in-java-how-can-i-reference-t
he-instance-define-in-a-nested-bxml-s-bxml-id-tp4022008p4022838.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.




RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
So, after digging into this some more, I begin to see what you mean.  If you don't use "inline='true'" on your "bxml:include" then there is no way (directly) to get access to the included file's serializer, and thus its namespace.  If you use "inline" (of course) then you have the possibility of name collisions.

One possible solution to this is to use a custom subclass of BXMLSerializer (that you would have to register using BXMLSerializer.getMimeTypes().put("bxml", your new Serializer class)) that would do something different with the namespace map.  The difficulty would be associating the namespace of the included file with the main file's namespace, since there is no connection (currently).

It definitely does seem like we *should* be able to deal with this situation more gracefully, but I'm at somewhat of a loss right now what to suggest.  Perhaps we could make a change, and pass some more information to an "include"d serializer that would tell it to put its variables into the parent's namespace as something like the bxml:id of the include element followed by ":" and the id.  Then for multiple levels of nesting you would get "a:b:c", and etc.  How that would work with the variable bindings, (i.e., using "serializer.bind(...)") I don't know.

Anyone else have thoughts?  *Perhaps* there is some way, as Karel is suggesting, of using namespace binding, but I'm not seeing that either.  Of course, making a Pivot change like this isn't likely to help with your deadline.

So, I guess my best suggestion at this point is to make wise choices about how you split up your BXML files, and how the "include" structure works, so that you don't have to do cross-file referencing.  And/or make judicious use of "inline='true'" to put the included variables into the main file's namespace.

Anybody else see something I'm not seeing?

Thanks,
~Roger

-----Original Message-----
From: Roger L. Whitcomb [mailto:Roger.Whitcomb@actian.com] 
Sent: Thursday, January 23, 2014 10:08 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Hi Mark,
	I assume you've read through the BXML Primer here: http://pivot.apache.org/tutorials/bxml-primer.html  It describes how namespaces work and the "bxml:include" semantics (including the "inline" attribute).  But, I think that the default behavior of making a separate namespace for each included BXML file would satisfy your requirements, unless I don't understand what you're trying to do.

Let us know,
~Roger

-----Original Message-----
From: Ripgiblet [mailto:mark@mrchambers.org] 
Sent: Thursday, January 23, 2014 3:12 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Hi Karel,

Thanks for the response, seemed like what I needed, but I cant seem to get it too work...
Bit of a deadline on this, later I will try compiling your code and check it works... I must be missing something...

regards,
Mark.



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/in-java-how-can-i-reference-the-instance-define-in-a-nested-bxml-s-bxml-id-tp4022008p4022838.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.





RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
Hi Mark,
	I assume you've read through the BXML Primer here: http://pivot.apache.org/tutorials/bxml-primer.html  It describes how namespaces work and the "bxml:include" semantics (including the "inline" attribute).  But, I think that the default behavior of making a separate namespace for each included BXML file would satisfy your requirements, unless I don't understand what you're trying to do.

Let us know,
~Roger

-----Original Message-----
From: Ripgiblet [mailto:mark@mrchambers.org] 
Sent: Thursday, January 23, 2014 3:12 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Hi Karel,

Thanks for the response, seemed like what I needed, but I cant seem to get it too work...
Bit of a deadline on this, later I will try compiling your code and check it works... I must be missing something...

regards,
Mark.



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/in-java-how-can-i-reference-the-instance-define-in-a-nested-bxml-s-bxml-id-tp4022008p4022838.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.



RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Posted by Ripgiblet <ma...@mrchambers.org>.
Hi Karel,

Thanks for the response, seemed like what I needed, but I cant seem to get
it too work...
Bit of a deadline on this, later I will try compiling your code and check it
works... I must be missing something...

regards,
Mark.



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/in-java-how-can-i-reference-the-instance-define-in-a-nested-bxml-s-bxml-id-tp4022008p4022838.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Posted by Karel Hübl <ka...@gemsystem.cz>.
Hi Mark,

May be you can use the containers getNamedComponent method. Sample app is attached.

Regards Karel



-----Original Message-----
From: Ripgiblet [mailto:mark@mrchambers.org] 
Sent: Wednesday, January 22, 2014 4:06 AM
To: user@pivot.apache.org
Subject: RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

This does not fix it, since property bindings still need to be in the same variable space as the included .bxml files.

Not sure on the relevance of this link, 

Karel Hübl wrote
> The model instance can be shared between parent and nested bxml files 
> and you bound the gui control properties to shared model. It is little 
> more complex, but you can see description of application archtecture 
> we use
> here:
> https://code.google.com/a/apache-extras.org/p/pivot-contrib/wiki/Appli
> cationArchitecture

Thanks anyway for the application example, might have some useful stuff in it, but it does not access an included bxml file.
And I don't think it can since unless you use inline, you cannot access the main model space...

I am trying to use Pivot to move GUI layout etc. into the xml file (with Style defined in the .json file) and all program logic etc. in JAVA. (Which I suspect is the core concept behind pivot.) What I need to be able to do is access the nested objects:
mUsernameTextInput = (TextInput)namespace.get("usernameTextInput");
and for a nested object maybe something like...
mUsernameTextInput = (TextInput)namespace.get("tab2.usernameTextInput");
This is so I can use generic .bxml in different parts of the application, with the same id's...
or allow id's to be set by variables, like bxml:id="$TextInputTab".

Anyway I have since done a work arround, by changing the .bxml files so that no TextInput fields are in generic bxml files and are in the same variable space, and then manually set them to have unique ID's.
But its a bit messy... 

Thanks for your response.

regards,
Mark.



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/in-java-how-can-i-reference-the-instance-define-in-a-nested-bxml-s-bxml-id-tp4022008p4022834.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Posted by Ripgiblet <ma...@mrchambers.org>.
This does not fix it, since property bindings still need to be in the same
variable space as the included .bxml files.

Not sure on the relevance of this link, 

Karel Hübl wrote
> The model instance can be shared between parent and nested bxml files and
> you bound the gui control properties to shared model. It is little more
> complex, but you can see description of application archtecture we use
> here:
> https://code.google.com/a/apache-extras.org/p/pivot-contrib/wiki/ApplicationArchitecture

Thanks anyway for the application example, might have some useful stuff in
it, but it does not access an included bxml file.
And I don't think it can since unless you use inline, you cannot access the
main model space...

I am trying to use Pivot to move GUI layout etc. into the xml file (with
Style defined in the .json file) and all program logic etc. in JAVA. (Which
I suspect is the core concept behind pivot.) 
What I need to be able to do is access the nested objects:
mUsernameTextInput = (TextInput)namespace.get("usernameTextInput");
and for a nested object maybe something like...
mUsernameTextInput = (TextInput)namespace.get("tab2.usernameTextInput");
This is so I can use generic .bxml in different parts of the application,
with the same id's...
or allow id's to be set by variables, like bxml:id="$TextInputTab".

Anyway I have since done a work arround, by changing the .bxml files so that
no TextInput fields are in generic bxml files and are in the same variable
space, and then manually set them to have unique ID's.
But its a bit messy... 

Thanks for your response.

regards,
Mark.



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/in-java-how-can-i-reference-the-instance-define-in-a-nested-bxml-s-bxml-id-tp4022008p4022834.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Posted by Karel Hübl <ka...@gemsystem.cz>.
Hi,

I suppose you need the reference to instance of nested bxml element to
manipulate it. You can do this indirect using property binding - see
http://pivot.apache.org/tutorials/property-binding.html.

Then to change for example the text property of nested TextInput you change
the value of bounded property. So you do not need the direct reference to
bounded TextInput, but you still need the reference to instance holding
property bounded value. 

The model instance can be shared between parent and nested bxml files and
you bound the gui control properties to shared model. It is little more
complex, but you can see description of application archtecture we use here:
https://code.google.com/a/apache-extras.org/p/pivot-contrib/wiki/Application
Architecture .

Regards Karel

-----Original Message-----
From: Ripgiblet [mailto:mark@mrchambers.org] 
Sent: Tuesday, January 21, 2014 7:53 AM
To: user@pivot.apache.org
Subject: Re: in java how can i reference the instance define in a nested
bxml's "bxml:id..."

Still the question remains...

How can you reference the objects in nested bxml files?

You cant always use inline, since the id: does not seem to be able to take a
variable... so you cant nest any bxml code with duplicate TextInput for
example if its in the same variable space, since you cant seem to make:
<bxml:script>
            var vTextInput = "TextInput" + vTab; </bxml:script> <TextInput
bxml:id="$TextInput" styles="{font:'Arial bold 28', color:'#000000',
            horizontalAlignment:'left'}"/>

Just says that the id is $TextInput and that it is a duplicate if you
include it again...
It works for actions but not for bxml:id...

So it seems you have to not make it inline and reference it somehow?



--
View this message in context:
http://apache-pivot-users.399431.n3.nabble.com/in-java-how-can-i-reference-t
he-instance-define-in-a-nested-bxml-s-bxml-id-tp4022008p4022830.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: in java how can i reference the instance define in a nested bxml's "bxml:id..."

Posted by Ripgiblet <ma...@mrchambers.org>.
Still the question remains...

How can you reference the objects in nested bxml files?

You cant always use inline, since the id: does not seem to be able to take a
variable... so you cant nest any bxml code with duplicate TextInput for
example if its in the same variable space, since you cant seem to make:
<bxml:script>
            var vTextInput = "TextInput" + vTab;
</bxml:script>
<TextInput bxml:id="$TextInput" styles="{font:'Arial bold 28',
color:'#000000',
            horizontalAlignment:'left'}"/>

Just says that the id is $TextInput and that it is a duplicate if you
include it again...
It works for actions but not for bxml:id...

So it seems you have to not make it inline and reference it somehow?



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/in-java-how-can-i-reference-the-instance-define-in-a-nested-bxml-s-bxml-id-tp4022008p4022830.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.