Jump to content
We've recently updated our Privacy Statement, available here ×

Passing Parameter to ad hoc view from BuiltInUserParameterProvider


nageshit2011

Recommended Posts

Hi,

I implemented ad hoc views & integrated in liferay using Iframe. Now i want to display data in the reports based on logged in user. So i implemented "CustomBuiltInUserParameterProvider.java". With hard coded "USER_ID" its working fine. Now i want to pass user data to "CustomBuiltInUserParameterProvider.java". But i dont have any idea, how to pass. Currently my data in liferay session.

Can u please guide me. Its urgent requirement for us.

Thanks & Regards,

VV Nagesh Bodapati.

 

 

 

Link to comment
Share on other sites

  • 10 months later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

Find the below code,

 

public class LiferayUserProfileBuiltInParameterProvider implements BuiltInParameterProvider
{
 
  private static final String LOGGED_IN_USER_PARAMETER_PREFIX = "LiferayUser";
  private static final String[] LOGGED_IN_USER_STANDARD_PARAMETERS = {LOGGED_IN_USER_PARAMETER_PREFIX};
  
  @SuppressWarnings("unchecked")
  public List<Object[]> getParameters(ExecutionContext context, List jrParameters, Map parameters)
  {
    List userProfileParameters = new ArrayList();
 
    for (String parameterName : LOGGED_IN_USER_STANDARD_PARAMETERS) 
{
 Object[] result = getParameter(context, jrParameters, parameters, parameterName);
 if (result != null) 
 {
userProfileParameters.add(result);
 }
    }
 
    return userProfileParameters;
  }
 
  @SuppressWarnings("unchecked")
  public Object[] getParameter(ExecutionContext context, List jrParameters, Map parameters, String name)
  {
      if ((name == null) || (!name.toLowerCase().startsWith("LiferayUser".toLowerCase()))) {
          return null;
        }
      try
      {
          Authentication auth = SecurityContextHolder.getContext().getAuthentication();
          if ((auth == null) || (!(auth.getPrincipal() instanceof MetadataUserDetails))) 
          {
            return null;
          }
          MetadataUserDetails userDetails = (MetadataUserDetails)auth.getPrincipal();
          String userName = userDetails.getUsername();
          return new Object[] { JRQueryExecuterAdapter.makeParameter(name, LiferayUser.class), liferayUser };
      }
      catch(Exception exception)
      {
          System.out.println("Exception Occured in LiferayUserProfileBuiltInParameterProvider - "+exception.getMessage());
      }
      return null;
  }
 
  public String getLiferayUserParameterPrefix() 
  {
    return LOGGED_IN_USER_PARAMETER_PREFIX;
  }
}

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...