struts2 namespace name issue - namespaces

Hi i am using struts2 and hibernate in my project. I need to use a namespace for my admin section so that i have used the namepace as companyAdmin and i have created a folder inside the web folder named companyAdmin and it is worked fine. But when i delete the folder companyAdmin from the web folder the struts show an error error message when trying to access the namespace. Is there a folder with name as namespace name is a must in struts2 for using the namespace. Also i can't able to use the namespace as "admin" even though i have created a folder in the web folder with a name admin.

Please be clear that Struts2 namespace is nothing related to folder/any other resource in your web-application.
Namespace inside Struts2 subdivides action configurations into logical modules, each with its own identifying prefix.Namespaces avoid conflicts between action names.
This is what doc say about namespace
Namespaces are not a path!
Namespace are not hierarchical like a file system path. There is one namespace level. For example if the URL /barspace/myspace/bar.action is requested, the framework will first look for namespace /barspace/myspace. If the action does not exist at /barspace/myspace, the search will immediately fall back to the default namespace "". The framework will not parse the namespace into a series of "folders". In the Namespace Example, the bar action in the default namespace would be selected.
I suggest you to go through the official documentation of Namespace to get an idea what they are and how they work inside S2
namespace-configuration

Related

ASP.NET core razor pages localization for inputmodel inside pagemodel

I have created a Resources folder inside my ASP.NET Core solution and have created resx files for translations. I have resx files for models, pages and controllers. I would like to know where to put a resx file inside the Resources folder when there is a inputmodel inside a pagemodel?
This is an old question and maybe not relevant now, but I just had the same problem and was able to figure it out, so I'll add what worked for me.
It is really just a minor detail. If we want the resource for the page model, we would have Resources\Pages\IndexModel.en.resx, for a class that's internal to that page model, we add a +InnerModel, ending up with Resources\Pages\IndexModel+InnerModel.en.resx
I created a GitHub repository with a working sample here -> https://github.com/joaofbantunes/AspNetCoreRazorPagesInnerModelLocalizationSample
lets assume that we have a razor page under pages folder as below:
Pages/MyPage.cshtml
and its model page:
Pages/MyPage.cshtml.cs
your resource folder is located in the Project root beside Pages folder as below:
Project Root
-- Pages
-- Resources
MyPages input model by default is:
MyPageModel
Naming of the resource files deffers according to view localization setup in your startup.cs file,
Dotted naming :
if you used per view resource files with "suffix" option:
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);
then you have to follow dotted naming for the resource files:
Resources/Pages.MyPage.en-US.resx // localization resource for view
Resources/Pages.MyPageModel.en-US.resx // localization resource for input model
Subfolder naming
if you used per view resource files with "Subfolder" option:
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddViewLocalization(LanguageViewLocationExpanderFormat.SubFolder);
then you have to create folder structure for resource files similar to the view folder strcuture:
Resources/Pages/MyPage.en-US.resx // localization resource for view
Resources/Pages/MyPageModel.en-US.resx // localization resource for input model
There is another option, which is using shared resource files, instead of creating one resource per view per language you may create only one resource file for all views per language, if you are intereseted in using shared resources you may visited this blog page: http://www.ziyad.info/en/articles/10-Developing_Multicultural_Web_Application

How to get the namespace of t4 template

I'm working on a code generation with T4 template. I'm generating multiple .cs files by one template and i need to write correct namespace for this files. Namespace depends on the template location.
How can i get the template namespace for generated .cs files?
I know the only one way to do this - explicit setted property "Custom Tool Namespace" for the template and then get this property via EnvDTE assembly. But this way is not ok for me, cause i need a locate a lot of copies this template for generate files in different propjects and i want to get namespace dynamically by the template location.
Can anyone help me?
Can you use EnvDTE's FileCodeModel to get the relative path of your template; and then use that to build your outputted namespaces?
You might want to browse through this post: http://t4-editor.tangible-engineering.com/blog/walking-the-visual-studio-code-model-with-t4-template.html

How can I tell PHPStorm to refactor namespaces and class names?

I've noticed when I move a file in PHPStorm, it doesn't adjust the namespace at all. My project uses PSR-0, so directory structure mirrors the namespacing. Is it possible to have PHPStorm adjust the namespace when a file is moved?
Also, when renaming a file the class name is not changed and I then have to go in and rename the class. Is it possible to rename a file and the class in a single step?
I'm using 7.1.3
I encountered the same issue. The reason was that I was trying to move the file (from project view), instead of moving the class (right click on the name in the source code).
If you use the F6 refactoring, it will allow you to move the class and change the namespace at the same time: PHPStorm docs
However, you do need to have the directory namespace mappings setup:
Because my application is a Laravel app the root directory was not the source of the namespacing. PHPStorm has a new option as of 8.0 that allows you to specify a directory as the namespace root: http://youtrack.jetbrains.com/issue/WI-22585

Configuring DisplayTag for individual pages

I have too many modules (around 90) in my project.
But I want to keep individual displaytag.properties file for each module rather than having single file for whole project.
How to achieve this.
I am using struts2
I think that you can configure each displaytag using the appropiate bundle, remember the bundle search order from S2 docs:
ActionClass.properties Interface.properties
Interface.properties (every interface and sub-interface)
BaseClass.properties (all the way to Object.properties)
ModelDriven's model (if implements ModelDriven), for the model object repeat from 1
package.properties (of the directory where class is located and every parent directory all the way to the root directory)
search up the i18n message key hierarchy itself
global resource properties
and from the docs for the DisplayTag library:
For the whole web application, create a custom properties file named "displaytag.properties" and place it in the application classpath. Displaytag will use the locale of the request object to determine the locale of the property file to use; if the key required does not exist in the specified file, the key will be loaded from a more general property file.
so i guess that the displaytag will search the config keys in the s2 available bundles.

Classes generated by XML Data Generator Tool are not contained within the specified namespace

I have the same problem as described in this connect issue
http://connect.microsoft.com/VisualStudio/feedback/details/577382/classes-generated-by-xml-data-generator-tool-are-not-contained-within-the-specified-namespace
"An XSD file using the XML Data Generator Tool within a C++/CLI project will create a set of classes that are NOT within a namespace. The classes should be within the namespace specified by the Namespace property of the XML Data Generator Tool. This was detected when upgrading a VS2008 project to VS2010."
I see the /namespace option is on the command line of the XML Data Generator tool but still it does not write the namespace.
In VS 2008
// This source code was auto-generated by xsd, Version=2.0.50727.3038.
//
namespace IOLib {
using namespace System;
ref class CPDS;
In VS 2010
// This source code was auto-generated by xsd, Version=4.0.30319.1.
//
using namespace System;
ref class CPDS;
Is there a way to force xsd tool to write the namespace too.
for xsd.exe the parameter /n: is used to specify the namespace. Don't put a space between the parameter and the value.
Example:
xsd myschema.xsd /c /n:MyNamespace
Visual Studio uses MSBuild to build the targets specified in the solution. They seem to be abandoning C++ in favor of VB and C#. VS 2010 uses settings in
C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets`
file. The XSD section is missing an entry namely "Namespace". I set mine to
Namespace ="%(Xsd.Namespace)"
and compliled the xsd and the classes are now in the namespace I specify in the projects property pages.