I18n in Struts-menu with Struts 2 - java

I've developed a menu using struts-menu 2.4.3 with Struts 2. It's working ok but I need to take the titles of the menus from a properties file (router-messages.properties). The whole application is internationalized like this. But it just doesn't work with struts-menu. Here is my menu-config.xml file:
<Menu name="mainMenu" title="" >
<Item name="ecfMenu" title="ECFs" roles="FISCO" location="DisconnectedEcfsSearch" />
<Item name="reportsMenu" title="Relatórios" roles="ADMIN" location="AlarmReportSearch"/>
<Item name="fiscoMenu" title="Fisco" roles="ADMIN" location="UpdateFiscoForm"/>
<Item name="alarmMenu" title="Alarmes" roles="ADMIN" location="AlarmNotification"/>
<Item name="userMenu" title="application.header.users" roles="ADMIN" location="UserSearch"/>
<Item name="consoleMenu" title="Console" roles="FISCO" location="ConsoleSearch"/>
</Menu>
Please notice that I'm trying to use a key to my properties file in the item 'userMenu'. All other items work, but not this one.
Here's my jsp:
<menu:useMenuDisplayer permissions="rolesAdapter" name="Velocity"
config="/WEB-INF/tabs.html">
<menu:displayMenu name="mainMenu" />
</menu:useMenuDisplayer>
I searched around and even found a guy with the same question but there was no response for him. =/
Does anybody know how to make struts-menu recognize that I'm using a key to a properties file and not a literal String??
Thanks!

Try this:
For the menu-config.xml:
<Menu name="mainMenu" title="" >
<Item name="userMenu" title="application.header.users" roles="ADMIN" location="UserSearch"/>
</Menu>
For the JSP:
Use this:
<%# taglib prefix="menu" uri="http://struts-menu.sf.net/tag-el"%>
Instead of this:
<%# taglib prefix="menu" uri="http://struts-menu.sf.net/tag"%>
Invoking the menu:
<menu:useMenuDisplayer bundle="messages" permissions="rolesAdapter" name="Velocity"
config="/WEB-INF/tabs.html">
<menu:displayMenu name="mainMenu" />
</menu:useMenuDisplayer>
For the bundle="messages" provide the name of your resource bundle.
I hope it works for you!

Related

tools:showIn="navigation_view" not working

When i append tools:showIn="navigation_view" to my code it's not showing. But in video which i watched from Youtube this is working fine. What is the problem? Also I can't add library called
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_home"
android:icon="#drawable/ic_main_home"
android:title="#string/home" />
<item
android:id="#+id/nav_timetable"
android:icon="#drawable/ic_subject_timetable"
android:title="#string/timetable" />
<item
android:id="#+id/nav_ogrnot"
android:icon="#drawable/ic_ogrnot"
android:title="#string/ogrnot" />
<item
android:id="#+id/nav_yemek_menu"
android:icon="#drawable/ic_yemek_menu"
android:title="#string/yemek_menu" />
<item
android:id="#+id/nav_homework"
android:icon="#drawable/ic_homework"
android:title="#string/homework" />
</group>
<item android:title="#string/optional">
<menu>
<item
android:id="#+id/nav_to_do_list"
android:icon="#drawable/ic_to_do_list"
android:title="#string/to_do_list" />
<item
android:id="#+id/nav_logout"
android:icon="#drawable/ic_logout"
android:title="#string/logout" />
</menu>
</item>
</menu>
I had the same issue with my code. The first thing I did was to delete my already created menu file (Android resource file) and start the process from the top.
Secondly, after creating the menu resource file, on a new line, after typing (tool:), press alt+enter to add this automatically for you... xmlns:tools="http://schemas.android.com/tools"... Then you can go ahead to type in tools:showIn=".....".
To know if this works, in line of code in tools:showIn, when typing the name in the quotes, just type "na'... if there are other popups or suggestions, then you're good to go.
Hope this helps.

What is a <selector> element?

I read the android manual to learn more about drawable and this is what I have came across. Stated in the android Developer:
item
Defines a drawable to use during certain states, as described by its attributes. Must be a child of a selector element.
1) I am confused about what a selector element is.
2) why do I have to include my item inside the selector?
Selector is the "container" element.
Take for example this playbutton.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false"
android:drawable="#drawable/pause" /> <!-- pressed -->
<item android:state_checked="true"
android:drawable="#drawable/play" /> <!-- focused -->
<item android:drawable="#drawable/pause" /> <!-- default -->
</selector>
(stolen from here)
It's a single button image that dynamically shows different images depending on whether it is currently pressed or not. The system can "select" the item from a list of items and so it was named selector, I guess.
Or "state list" like in the documentation: http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

What is this Android drawable background resource?

I have just started learning Android, currently going through the tutorials on the Google Android developer website, so far not that impressed as there are a lot of things that go unexplained.
On the tutorial "Styling the Action Bar", it has the following XML style resource:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
</style>
</resources>
(Android 2.1+ support)
At no point does it mention what the #drawable/actionbar_background is meant to be? As it is #drawable is this an image? I wouldn't understand why it would be as it's meant to be colouring the action bar background.
Any help would be greatly appreciated!!!!!!! :)
The line
<item name="background">#drawable/actionbar_background</item>
translates to English like
Add to this style an item representing a property called "background".
As the value of this property, set a resource of type "drawable" with
name "actionbar_background".
In this case the script will look for an image in the resources folder "drawable" the name of which matches the given one. If the line was
<item name="text">#string/actionbar_title</item>
The script would look in res/values for a resource defined as <string> with "name" property "actionbar_title".
In the layout files for Android, the '#' symbol followed by a word like 'drawable' or 'style', refers to a path and file in the res or resource folder.
http://developer.android.com/guide/topics/resources/drawable-resource.html
<item name="android:background">#drawable/actionbar_background</item> sets your actionBar's background to drawable(image) resource which is located in your project -> drawable folders.
I guess you can also use color to set your background like this:
<item name="android:background">#android:color/black</item>

How to expand android ActionBar?

How can i expand the actionbar like PlayNewsstand application and the image below :
What i am looking for found it here.
For your concern try using this in your manifest file ..
yourapp:showAsAction="ifRoom"
Ex:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
yourapp:showAsAction="ifRoom" />
...
</menu>
Complete reference :: http://developer.android.com/guide/topics/ui/actionbar.html

android: Custom Submenus

I want to create a customized submenu where i can add an "about page" to my application. So my submenu would just be a text view with a bunch of info. Im currently defining my menu in XML. Any help or links would be great, thanks!!!
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/settings_menu"
android:title="Settings" />
<item android:id="#+id/about_menu"
android:title="About">
<menu>
<item android:id="#+id/about_submenu"
android:title="Tip Message" />
</menu>
</item>
<item android:id="#+id/quit_menu"
android:title="Quit" />
</menu>
Also just out of curiosity, how would i define a more complex custom submenu, like one that takes user input from a keyboard.
I think it's easier to make something look like a menu. Try Activity with #android:drawable/menu_submenu_background as a background for example.

Categories