Liferay 7 customize Edit User page

Jason Chee, modified 7 Years ago. Junior Member Posts: 52 Join Date: 9/24/18 Recent Posts

I have requirements to customize the Edit User page as the client wants to do the following:

- add more Prefix choices

- remove Suffix field

- have predefined Job Title (dropdown style)

 

Is there a way to edit the existing Edit User page to do these? I've read that there's a need to edit the database in order to achieve it. Also, most solutions I found in this forum refer to older Liferay and I can't apply to Liferay 7.

 

 

 

thumbnail
Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
Jason Chee:

I have requirements to customize the Edit User page as the client wants to do the following:

  • add more Prefix choices
  • remove Suffix field
  • have predefined Job Title (dropdown style)

Two of those requirements are theoretically achievable by modifying global language keys for all of the languages you wish to support in your Liferay instance.

The last requirement will require an actual code-level customization.

    • If you want the job title to be a select box rather than a text input field, you will need to customize details.jsp in com.liferay.users.admin.web and com.liferay.my.account.web (when rebuilding from source, you only need to change one file because they're copied as part of the build process, but when customizing Liferay, you need to change it in both places).
    Jason Chee, modified 7 Years ago. Junior Member Posts: 52 Join Date: 9/24/18 Recent Posts

    Hi Minhchau, thanks for your response! 

    However, I'm not able to find the files you mentioned. My folder structure is like below:

     

    I can't seem to locate the files you mentioned. I feel like there's something really simple that I am missing!

    thumbnail
    Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
    Jason Chee:

    However, I'm not able to find the files you mentioned.

    The files are buried inside of zip files in a regular bundle, and normally people use the extension points described in the online documentation to make it easier to comply with Liferay's open source license agreement, which means you don't actually need to know where the file actually is in your bundle (just a general idea of what you need to do for customization is sufficient).

    If, out of curiosity, you want to see the actual code that is used with your version of Liferay:

    • Language*.properties are inside of the content folder of tomcat-8.0.32/webapps/ROOT/WEB-INF/lib/portal.impl.jar
    • details.jsp are inside of the META-INF/resources/user folder of com.liferay.users.admin.web-[VERSION].jar inside of the osgi/marketplace/Liferay Foundation.lpkg
    Jason Chee, modified 7 Years ago. Junior Member Posts: 52 Join Date: 9/24/18 Recent Posts

    Hi again Minhchau, sorry for the late response. I've been trying to do this but still not getting it. I manage to do it by replacing the portal.impl.jar, however I want to do it the right way following your tutorial.

     

    Help me understand the following 

    "Once you know the keys to override, create a language properties file for the locale you want (or the default Language.properties file) in your module’s src/main/resources/content folder. In your file, define the keys your way. For example, you could override the publish key."

     

    Currently I only have a theme deployed. I don't have any module. When the above instruction mentions "in your module’s src/main/resources/content folder", where would that be?

     

     

    thumbnail
    Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
    Jason Chee:

    Currently I only have a theme deployed. I don't have any module. When the above instruction mentions "in your module’s src/main/resources/content folder", where would that be?

    The tutorial assumes you know how to create a new OSGi module, following the instructions on Creating Projects with Blade CLI, and that would have a src/main/resources folder that you could add a content folder to.

    Jason Chee, modified 7 Years ago. Junior Member Posts: 52 Join Date: 9/24/18 Recent Posts

    I use Liferay IDE and I have tried creating modules before. However, in the context of making global changes to the Language.properties, what kind of module am I suppose to create?

    thumbnail
    Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
    Jason Chee:

    I use Liferay IDE and I have tried creating modules before. However, in the context of making global changes to the Language.properties, what kind of module am I suppose to create?

    Since the tutorial has you create everything without relying on any boiler plate code being auto-generated for you, it shouldn't matter.

    Jason Chee, modified 7 Years ago. Junior Member Posts: 52 Join Date: 9/24/18 Recent Posts
    Minhchau Dang:

    Two of those requirements are theoretically achievable by modifying global language keys for all of the languages you wish to support in your Liferay instance.

    The last requirement will require an actual code-level customization.

      • If you want the job title to be a select box rather than a text input field, you will need to customize details.jsp in com.liferay.users.admin.web and com.liferay.my.account.web (when rebuilding from source, you only need to change one file because they're copied as part of the build process, but when customizing Liferay, you need to change it in both places).

      Hey Minhchau, following the "modifying global language keys" tutorial, I can change the text of sign-in. However changes made to lang.user.name.prefix.values and lang.user.name.suffix.values don't work. Any idea what's the difference?

       

       

       

       

      thumbnail
      Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
      Jason Chee:

      I can change the text of sign-in. However changes made to lang.user.name.prefix.values and lang.user.name.suffix.values don't work. Any idea what's the difference?

      Do you have your code available anywhere? I started a build of 7.0.x and followed the tutorial, and modifying lang.user.name.prefix.values and lang.user.name.suffix.values worked just fine.

      With that being said, I was mistaken on how lang.user.name.field.names works, since it only removes the field from being considered when generating full names but leaves the field on the page. This means that you would need to modify details.jsp for that one as well.

      Edit: Never mind, I was actually right the first time about lang.user.name.field.names influencing fields on the details page. It just needed a server restart, since it looks like it only is able to do the replacement once. I'm guessing that's what you need as well.

      Jason Chee, modified 7 Years ago. Junior Member Posts: 52 Join Date: 9/24/18 Recent Posts

      These are my codes, of which only the edited value of sign-in  shows.

       

      Language.properties:

      lang.user.initials.field.names=first-name
      lang.user.name.field.names=prefix,first-name
      lang.user.name.prefix.values=Prefix A, Prefix B
      sign-in=Test Value

      CustomLanguage.java:

      package custom.language;
      import java.util.Enumeration;
      import java.util.ResourceBundle;
      import org.osgi.service.component.annotations.Component;
      import com.liferay.portal.kernel.language.UTF8Control;
      
      @Component(
              property = { "language.id=en_US" },
              service = ResourceBundle.class
      )
      
      public class CustomLanguage extends ResourceBundle {
              private final ResourceBundle resource = ResourceBundle.getBundle(
                  "content.Language", UTF8Control.INSTANCE);
      
              @Override
              public Enumeration<String> getKeys() {
                  return resource.getKeys();
              }
      
              @Override
              protected Object handleGetObject(String key) {
                  return resource.getObject(key);
              }
      }

       

      My module in Liferay workspace:

      Jason Chee, modified 7 Years ago. Junior Member Posts: 52 Join Date: 9/24/18 Recent Posts

      I'm not sure what happened but the changes have reflected all of a sudden after multiple times of redeploying. I just tried changing the list of prefixes once more and yet again, the changes don't reflect while changes to other keys such as first-name reflect immediately. Tried clearing cache and no luck as well. Seems like some changes are immediate while others are not? 

       

      Strange, but problem kinda solved I guess! Thanks for your time MinhChau.