Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MenuBar data is not initialized while defined in fx:Declarations as XMLList which retrieves label from resource manager #545

Closed
nihavend opened this issue Nov 3, 2019 · 1 comment
Assignees

Comments

@nihavend
Copy link
Contributor

@nihavend nihavend commented Nov 3, 2019

In the test case below two methods implemented for menubar initialization.

  1. MenuBar data defined as XMLList variable in actionscript (fx:Script) -- Working
  2. MenuBar data declared as XMLList in fx:Declarations -- Working Partially

In the second case, the second menu item getting label from resource manager is the problematic part which is not displayed correctly.

Here is the code :

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.apache.org/royale/spark"
			   xmlns:mx="library://ns.apache.org/royale/mx"
			   paddingBottom="0" paddingTop="0" paddingLeft="0" paddingRight="0"
			   height="100%" width="100%" 
			   >
	
	<fx:Metadata>
		[ResourceBundle("messages")]
	</fx:Metadata>
	
	<fx:Script>
		<![CDATA[
			
			import mx.resources.ResourceManager;
			import mx.collections.XMLListCollection;
			import mx.events.FlexEvent;
			import mx.events.MenuEvent;
			
			
			[Bindable]
			public var menuBarData1:XMLListCollection = new XMLListCollection();
			
			[Bindable]
			public var menuBarData2:XMLListCollection = new XMLListCollection();
			
			
			private var menubarXML:XMLList =
				<>
					<menuitem label="Menu1" data="top">
						<menuitem label="MenuItem 1-A" data="1A"/>
						<menuitem label="MenuItem 1-B" data="1B"/>
					</menuitem>
					<menuitem label="Menu2" data="top">
						<menuitem label="MenuItem 2-A" type="check"  data="2A"/>
						<menuitem type="separator"/>
						<menuitem label="MenuItem 2-B" >
							<menuitem label="SubMenuItem 3-A" type="radio"
								groupName="one" data="3A"/>
							<menuitem label="SubMenuItem 3-B" type="radio"
								groupName="one" data="3B"/>
						</menuitem>
					</menuitem>
				</>;
			
			public function onCreationComplete():void {
				
			}


			protected function creationCompleteHandler1(event:FlexEvent):void
			{	
				menuBarData1 = new XMLListCollection(menubarXML);
			}
			
			protected function creationCompleteHandler2(event:FlexEvent):void
			{

				var roleInfo:String = "ADMIN";
				
				var tmpXmlList:XMLListCollection = new XMLListCollection();
				tmpXmlList.source = menuDataXMLList;
				
				
				/*
					RoleFilters is a custom class that is filtering the xml nodes 
					according to the given role eg:ADMIN, OPREATION, VIEW
				 	Not directly related the with the bug that is why commented
				*/
				// tmpXmlList = RoleFilters.deleteRoledMenuItems(tmpXmlList, roleInfo);
				
				menuDataXMLList = tmpXmlList.source.copy();
				
				menuBarData2.source = menuDataXMLList;
				
				menuBarData2.refresh();

			}
			
			protected function itemClickHandler(event:MenuEvent):void {
			}
			
		]]>
	</fx:Script>
	
	<fx:Declarations>
		<fx:XMLList id="menuDataXMLList">
			<menuitem label="label-1">			
				<menuitem label="label-1-1"/>			
				<menuitem label="label-1-2"/>			
			</menuitem>
			<menuitem label="{resourceManager.getString('messages', 'configuration')}" id="admin" role="{UserRole.ADMIN}">			
				<menuitem label="label-2-1"/>			
				<menuitem label="label-2-2"/>			
			</menuitem>
		</fx:XMLList>
	</fx:Declarations>	
	
	<s:layout>
		<s:VerticalLayout gap="10" paddingRight="10" paddingLeft="10" paddingTop="10" paddingBottom="20" />
	</s:layout>

	
	<mx:MenuBar id="menuBar_fx_Script" width="100%" dataProvider="{menuBarData1}" horizontalCenter="0"
				itemClick="itemClickHandler(event)" 
				labelField="@label" 
				creationComplete="creationCompleteHandler1(event)"/>

	<mx:MenuBar id="menuBar_fx_Declarations" width="100%" dataProvider="{menuBarData2}" horizontalCenter="0"
				itemClick="itemClickHandler(event)" 
				labelField="@label" 
				creationComplete="creationCompleteHandler2(event)"/>
</s:Application>
@nihavend nihavend changed the title MenuBar data is not initialized while defined in fx:Declarations as XMLList MenuBar data is not initialized while defined in fx:Declarations as XMLList which retrieves label from resource manager Nov 3, 2019
@aharui aharui self-assigned this Nov 5, 2019
@nihavend

This comment has been minimized.

Copy link
Contributor Author

@nihavend nihavend commented Nov 9, 2019

@aharui, the header is rendered after your fix but the sub menu items are still have the same issue.

e.g.

	<fx:Declarations>
		<fx:XMLList id="menuDataXMLList">
			<menuitem label="label-1">			
				<menuitem label="label-1-1"/>			
				<menuitem label="label-1-2"/>			
			</menuitem>
			<menuitem label="{resourceManager.getString('messages', 'configuration')}" id="admin" role="{UserRole.ADMIN}">			
				<menuitem label="label-2-1"/>			
				<menuitem label="{resourceManager.getString('messages', 'configuration')}" id="admin" role="{UserRole.ADMIN}"/>			
			</menuitem>
		</fx:XMLList>
	</fx:Declarations>	

May we go through this thread or file a new issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.