How get programmatically Liferay default language or locale?
Check the com.liferay.portal.kernel.util.LocaleUtil class methods:
LocaleUtil.getDefault() - returns default locale,
LocaleUtil.toLanguageId(locale) - to get language ID from locale.
P.S. Note that LocaleUtil uses ThreadLocal to store defaul locale, so if you're doing this in new thread that you created, you should first call com.liferay.portal.security.auth.CompanyThreadLocal.setCompanyId(long companyId) method - this one will initialize LocaleThreadLocal and TimeZoneThreadLocal with default locale and timezlone.
Related
If I create a UserControl, to create and edit an instance of a data class e.g. Person in C# WindowsForms (call it PersonControl), the framework automatically adds an instance of Person in PersonControl.Designer with some default values for the properties and fills the item controls with those values. This behavior has a number of side effects which I would like to avoid.
Question: is there a defined way to prevent creation of a data class instance in UserControl.Designer?
I think you missing the DesignerSerializationVisibility attribute. If you have a custom control every public property that you add will automatically be serialized. You can use this attribute to disable the serialization for a property. I also recommend to add the Browsable attribute which will hide the property from the designer. If you want more control over serialization, like you want to serialize only when another property is set to true you can create a special named method which will then called by the designer Defining Default Values with the ShouldSerialize and Reset Methods. There was a MSDN Magazine where a lots of winform learning resource was relased there are some gems about winform internal working. If you interested in you can quickly look trhrough it. My favorite is. Create And Host Custom Designers With The .NET Framework 2.0
Sorry but i didn't mention another attribute DefaultValue You can use the attribute the following way.
public partial class PersonEditControl : UserControl
{
[DefaultValue(null)] // This attribute tells the designer if the property value matches what we specified in the attribute(null) it should not store the property value.
public PersonData? Person { get; set; }
public PersonEditControl()
{
InitializeComponent();
}
}
I am trying to change the language of portlet title, but didn't succeed!
I went through the various link from liferay's forum, but unable to achieve my task.
Example:1
Example:2
Details:
I am using following locales fr_FR and zh_CN,with the following values in the concerned properties file
javax.portlet.title.1_WAR_microblogsportlet=News
javax.portlet.title.1_WAR_microblogsportlet=nouvelles(for fr_FR)
javax.portlet.title.1_WAR_microblogsportlet=新聞(for zh_CN)
resource bundle is set in portlet.xml as given:
<portlet-name>1</portlet-name>
<display-name>Microblogs</display-name>
<portlet-class>com.liferay.microblogs.microblogs.portlet.MicroblogsPortlet</portlet-class>
<resource-bundle>content.Language</resource-bundle>
You just need to have property with key as "javax.portlet.title", no need to put your portlet ID as part of key.
Name the localized properties files and put property value as below.
Language.properties
javax.portlet.title=News
Language_fr.properties
javax.portlet.title=nouvelles
Language_zh.properties
javax.portlet.title=新聞
Then liferay displays portlet in corresponding language depending on user's locale.
You may test in one of below ways.
For User -
In current user profile -> Display Settings, Select language as French and then visit the page having your portlet. It should display title in french instead of english.
Change in URL
You may also specify locale in page URL as described in liferay 6.1 documentation
http://localhost:8080/fr/<your page url>
Using Language portlet
Add Language portlet on your page and clicking on French flag changes locale to french and the page should display portlet title in French.
for a my current project I would like to overide the context.getUser() method to return a custom pojo which extends the default object returned?
The reason I would like to do is so that I dont have to use the sessionScope technique of saving person specific data and just can call context.getUser() instead (which checks which user is logged on (or anonymous) and retrieves all data needed without.
I would not override context.getUser() - you don't know what else that may require. Have you looked at the userBean and or peopleBean from the extension library? You could use that to get any information you need, then if you need more, or want to create a custom class that extends those beans, install it as a scoped bean in your application, and then use it as the base for your own getUser().
This question already has an answer here:
h:inputText which is bound to Integer property is submitting value 0 instead of null
(1 answer)
Closed 7 years ago.
I have integer properties from my bean binded to inputtext UI elements in jsp pages.
initially when they are rendered, default value of this integer properties is null.
Now when i am submitting the form without changing this inputtext fields, this fields are set to integer value zero in bean, even though ui text field is blank.
As i want to track the changes to fields and update only those fields which are changed in configuration files, but this is giving me problem as it results into updates to all integer field.
I am using jsf 1.2
This issue is however specific to EL implementation of Tomcat (Glassfish for example, doesn't expose this stupid behaviour). It used to work "as intuitively expected" until Tomcat 6.0.16. Then they discovered that it actually violated the literal EL spec and fixed it. After a lot of critism, they made it configureable from 6.0.17 and upwards. You can turn it off by adding the following VM argument:
-Dorg.apache.el.parser.COERCE_TO_ZERO=false
This is IMO better than hacking into getters/setters. You don't want to pollute your model like that.
Related questions:
inputtext submitting value 0 instead of null
COERCE_TO_ZERO at runtime
The JSF EL specification decrees that null is to be converted to 0 prior to assigning a property of numeric type. (See the chapter on coercion rules). An issue has been filed about this, but is being ignored by the spec people.
There are no really pretty solutions. The easiest is to convert 0 back to null in the setter, but that assumes 0 is never a valid input. Other alternatives include having the setter and getter receive/return a non-numeric type such as String, and do the conversion to/from Integer in the setter/getter. That however means you would detect non-numeric inputs too late in the JSF life cycle, so you also need an additional validator/converter to handle that.
Edit: Websphere 7.0.0.11 doesn't coerce null to 0.
See that very complete answer by BalusC.
He says you can set the system property org.apache.el.parser.COERCE_TO_ZERO to false, but you can also write a ServletContextListener which would set it when your webapp starts.
For Websphere Users, define an user defined JVM System Property, and it works!
Found this link in the IBM support website for Websphere users.
Basically here are the steps:
You set the org.apache.el.parser.COERCE_TO_ZERO property using the
administrative console as follows:
Expand Servers, select WebSphere Application Servers, and then click on the appropriate server from the list.
Under Server Infrastructure, expand Java and Process Management > Click on Process definition.
Under Additional Properties, click Java virtual Machine.
Under Additional Properties, click Custom properties.
Click New and add the org.apache.el.parser.COERCE_TO_ZERO property with the value of false if you do NOT want a null value coerced to
zero.
Click Save to save the change and restart the WebSphere
Application Server to ensure the change takes place. Default value:
true
Could someone point me in the direction of how to create a custom "Inject" attribute with Ninject?
I would like to do the following:
InjectView - custom "inject" attribute
When a property with this attribute is to be injected, the injected value is to be loaded from a "ViewManager" class.
I found an example with ISelector to decide if the property / filed is to be injected, however I couldn't find out how to add a custom "injection strategy" for this - I would like to delegate the injection of the actual value to my ViewManager.
It's already supported and can be done with a simple configuration of the kernel.
new StandardKernel(new NinjectSettings() { InjectAttribute = typeof(MyOwnInjectAttribute) };
I solved this by adding a custom IInjectionHeuristic which allows injecting by my custom attribute. Then I also added a custom IBindingResolver which adds an additional binding per type that is resolved - this binding has a condition checking for the custom attribute, so that it doesn't break any previous bindings...
Tha bindings created by the custom IBindingResolver sets a local "ProviderCallback", which utilizes the extracted property and passes the request to an internal ViewRegionManager instance.
Hope this helps in case anyone wants to do something similar in the future.