Base solution for your next web application

Activities of "jeromevoxteneo"

Hello,

I'm trying to make my custom attribute that extend DisplayNameAttribute to make it localized. But I cannot get the value from the languageTextManager nor from the localizationManager.

Here is my attribute for LocalizedDisplayName

using System;
using System.ComponentModel;
using System.Globalization;
using Abp.Dependency;
using Abp.Localization;
using Abp.Runtime.Session;

namespace iExpertise.Localization
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Method, AllowMultiple = false)]
    public class LocalizedDisplayNameAttribute : DisplayNameAttribute
    {
        private IApplicationLanguageTextManager _languageTextManager;
        private ILocalizationManager _localizationManager;
        //private IAbpSession _abpSession;
        private string _originalName;
        public LocalizedDisplayNameAttribute(string displayName)
            : base()
        {
            _originalName = displayName;
        }

        public override string DisplayName
        {
            get
            {
                if (_languageTextManager == null)
                {
                    _languageTextManager = IocManager.Instance.Resolve<IApplicationLanguageTextManager>();
                    _localizationManager = IocManager.Instance.Resolve<ILocalizationManager>();
                    //_abpSession = IocManager.Instance.Resolve<IAbpSession>();
                }
                var translation = _localizationManager.GetString(iExpertiseConsts.LocalizationSourceName,
                    _originalName);
                var translation2 = _languageTextManager.GetStringOrNull(null, iExpertiseConsts.LocalizationSourceName,
                    CultureInfo.CurrentCulture, _originalName);
                return translation;
            }
        }
    }
}

I put a breakpoint at the return translation and it results that: translation is [Task type id_Label] translation2 is null

I wanted to be sure that my key that was added in the xml file was ok, so I navigated to the languages list and see my entry and put a breakpoint inside of the EditTextModal of LanguagesController, the translation here is ok.

In PreInitialize method of Core module I have:

//Add/remove localization sources
            Configuration.Localization.Sources.Add(
                new DictionaryBasedLocalizationSource(
                    iExpertiseConsts.LocalizationSourceName,
                    new XmlEmbeddedFileLocalizationDictionaryProvider(
                        Assembly.GetExecutingAssembly(),
                        "iExpertise.Localization.iExpertise"
                        )
                    )
                );

I cannot understand why my localization is ok in LanguagesController and not in my custom attribute in Core project.

Thanks for help

any idea ?

Yeah didn't know about this existing attribute

It's working, I was tired and set a wrong key in the attribute key value :oops:

Do you have similar attribute for required and string length attributes that can be localized ?

Thank for the help

On my project, I added jquery-validate-unobstrusive.js and for the popup I was needed to trigger manual validation (in the init function) :

//Setup unobtrusive validation at client side if (!_$roomForm.data('unobtrusiveValidation')) { $.validator.unobtrusive.parse('form[name=RoomForm]'); _$roomForm.data('unobtrusiveValidation').validate({ ignore: "" }); }

Hello,

I have trouble in my code actually and for example when the user set a wrong password the login method in AccountController throw a UserFriendlyException that's work fine.

But I don't get the right error message in the popup. I put some console.log in js file and it seems that the problem is :

.fail(function (jqXHR) {
                    console.log('fail ajax', jqXHR);
                    if (jqXHR.responseJSON && jqXHR.responseJSON.__abp) {
                        abp.ajax.handleResponse(jqXHR.responseJSON, userOptions, $dfd, jqXHR);
                    } else {
                        abp.ajax.handleNonAbpErrorResponse(jqXHR, userOptions, $dfd);
                    }
                });

there is no responseJSON but responseText

In preview I get the right error:

Login failed!

Description : Une exception non gérée s'est produite au moment de l'exécution de la requête Web actuelle. Contrôlez la trace de la pile pour plus d'informations sur l'erreur et son origine dans le code. 

Détails de l'exception: Abp.UI.UserFriendlyException: Login failed!

Erreur source: 


Ligne 224 :                    return loginResult;
Ligne 225 :                default:
Ligne 226 :                    throw _abpLoginResultTypeHelper.CreateExceptionForFailedLoginAttempt(loginResult.Result, usernameOrEmailAddress, tenancyName);
Ligne 227 :            }
Ligne 228 :        }

Fichier source : C:\projects\dotnet-abpzero-iexpertise\iExpertise.Web\Controllers\AccountController.cs    Ligne : 226

I don't know where is my mistake, I don't change the code that call the login action:

abp.ui.setBusy(
                null,
                abp.ajax({
                    contentType: app.consts.contentTypes.formUrlencoded,
                    url: $loginForm.attr('action'),
                    data: $loginForm.serialize()
                })
            );

I just check in last version of aspnet zero template and all works fine. Only my code failed :(

Do you have idea why I get this behavior ?

After further investigation (add symbol from Abp boilerplate framework in order to debug OnException override method in AbpController):

// If custom errors are disabled, we need to let the normal ASP.NET exception handler
            // execute so that the user can see useful debugging information.
            if (!context.HttpContext.IsCustomErrorEnabled)
            {
                base.OnException(context);
                return;
            }

IsCustomErrorEnabled is false.

What define is this boolean value is false or true?

Here is my config:

<customErrors mode="Off">
      <error statusCode="404" redirect="~/Error/E404" />
    </customErrors>

Ok after switching CustomErrors from Off to On the behavior is ok.

Thank you

I use jtable to display custom localized entry like that:

name: {
                    title: app.localize('Name'),
                    width: '10%',
                    display: function (data) {
                            return app.localize(data.record.nameKey);
                    }
                },

NameKey is the key matching with the table AbpLanguageTexts

That's works fine until I want to change the value from my popup. When i click on save, the jtable is reloaded but the value returned by app.localize is still the previous value and not the updated one.

I was wondering if there is a way in the framework to force a refresh of the app.localize without the need to reload the whole page ? Or maybe a way to update one value of the object for the key that is updated?

Thanks,

Hello,

I have the same need in my aspnet zero MVC / Jquery application but I don't have the api endpoint available.

What is the version of Abp Zero needed ?

Thanks

Showing 1 to 10 of 23 entries