function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ali abdullahali abdullah 

passing parameters from visual force to Controller is not working , its showing Null value.

hello,

 

i am new to visual force and apex and will appreciate the help on below.

 

i created a table in VF and retrieving the data like consultants , no of project and no of tasks from from the controller. its working fine but i need to click one of the consultants from the list above to get the detail report on the other page. i am trying to pass some parameters once "Onclick" function is performed but its returning null when i am clikcing on one of the consultant to get the reports on new page. below is my VF page.

 

Visual Force Page :

 

<apex:page controller="Consultant_Information">

<script type="text/javascript">
      function loadReports(Alias){
        if(typeof AF_LoadReports  == "function") {AF_LoadReports(Alias);}
      }
  </script>


  <apex:form >
  <apex:actionFunction name="AF_LoadReports" action="{!loadReports}" >
  <apex:param name="Alias" assignTo="{!Alias1}" value="" />    
  </apex:actionFunction>
  <apex:pageBlock title="Consultant Summary" >
  <apex:PageBlockSection columns="1" >
 <apex:pageBlockTable value="{!Items}" var="item">

 
<apex:column headerValue="Consultant" value="{!item.theUser.Name}" onclick="javascript&colon;AF_LoadReports('{!item.theUser.Alias}')"/>
<apex:column headerValue="Department" value="{!item.theUser.Division}"/>
<apex:column headerValue="Active Projects" value="{!item.noProjects}"/>
<apex:column headerValue="Active Tasks" value="{!item.noTasks}"/>
<apex:column headerValue="Last Login Date" value="{!item.theUser.LastLoginDate}"/>
</apex:pageBlockTable>
  </apex:PageBlockSection>
 
 
 
 
  
   
       
     </apex:pageBlock>

   
  </apex:form>
  </apex:page>

 

 

 

and below is my controler

 

public with sharing class Consultant_Information {
 public Consultant_Information(){
  loadConsultants();
 }
 
 public class userWrap{
                public User theUser{get;set;}
                public integer noProjects{get;set;}
                public integer noTasks{get;set;}
             
   }
public PageReference loadReports(){  
 String Alias1 =ApexPages.currentPage().getParameters().get('Alias');
 PageReference pageRef = new PageReference('https://c.na7.visual.force.com/apex/pConsultantSummary?Alias'+'='+Alias1);                    
  pageRef.setRedirect(true);
 
  return pageRef;
  }
 
public List<userWrap> listConsultant = new list<userWrap>();
  
public List<userWrap> getItems() {return listConsultant;}
 
 private void loadConsultants(){ 
 listConsultant.clear();
 List<User> users = new List<User>([Select u.Name, u.Id, u.Alias, u.Division, u.LastLoginDate From User u where u.IT_User__c = true and u.IsActive = true order by u.Name]);
 List<AggregateResult> Projects = new List<AggregateResult>([Select count(p.Id) noProjects, p.OwnerId from Project__c p where p.Project_Life_Cycle_Stages_2__c <> 'Closed' group by p.OwnerId]);
 List<AggregateResult> Tasks = new List<AggregateResult>([Select count(t.Id) noTasks, t.OwnerId from Task__c t where t.Task_Status__c <> 'Closed' group by t.OwnerId]);

 for(User u : users){
  userWrap wrap = new userWrap();
  wrap.theUser = u;
   for(AggregateResult r : projects){
   if(r.get('OwnerId') == u.Id){wrap.noProjects = (r.get('noProjects')==null?0: integer.valueOf(r.get('noProjects'))) ;}
  }
  for(AggregateResult r : tasks){
   if(r.get('OwnerId') == u.Id){wrap.noTasks = (r.get('noTasks')==null?0: integer.valueOf(r.get('noTasks')));}
  }
  listConsultant.add(wrap);
  }
  
 }
  
}

Best Answer chosen by Admin (Salesforce Developers) 
aamDevaamDev

Hi Ali,

 

I'm glad you were able to resolve the syntax error. I apologize if I misunderstood earlier, but the sample code I gave you will create a new column with the Aliases. If you want the name to be seen but the alias to be passed to the webaddress, replace the alias field within the outputlink tag with the name field instead. I'm sorry if I assumed too much with respect to your vf knowledge.

 

As for your web address not showing the value you want, I'd have to think that your javascript is incorrect. Try replacing the entire the javacript link to a regular url and removing it from your controller class.

 

Instead of :

 

<apex:column headerValue="Consultant">
<apex:outputLink value="javascript&colon;AF_LoadReports('{!item.the​User.Alias}')">{!item.theUser.Alias}</apex:outputLink>
</apex:column>

 

put:

 

<apex:column headerValue="Consultant">
<apex:outputLink value="https://c.na7.visual.force.com/apex/pConsultantSummary?Alias={!item.the​User.Alias}">{!item.theUser.Alias}</apex:outputLink>
</apex:column>

 

This should work.

All Answers

aamDevaamDev

Ali,

 

I think your problem is that you're putting the link on the column itself instead of the individual line item (consultant).

 

Try this instead:

 

 

<apex:column headerValue="Consultant">
	<apex:outputLink value="javascript&colon;AF_LoadReports('{!item.theUser.Alias}')">{!item.theUser.Alias}</apex:outputLink>
</apex:column>

 

I hope this helps.

 

Adriel

 

 

ali abdullahali abdullah

thanks for the reply Dev

 

i just copied your line below this line in my visual force page : <apex:column headerValue="Consultant" value="{!item.theUser.Name}"/>

 

the complete code is below. but the system is throwing this error , Error: The element type "apex:outputLink" must be terminated by the matching end-tag "</apex:outputLink>" even though its terminated by the matching end tag.

 

<apex:column headerValue="Consultant" value="{!item.theUser.Name}"/>
<apex:column headerValue="Consultant">
    <apex:outputLink value="javascript&colon;AF_LoadReports('{!item.the​User.Alias}')">{!item.theUser.Alias}</apex:outputL​ink>
</apex:column>

 

 

 

ali abdullahali abdullah

just to make it more clear , i used onclick function so that i can click on the "!item.theUser.Name" which is showing  showing the name of the consultants in the table , so when i click on the name system will pass navigate to new page with alias of the name added in the end of the webadress.

 

currently web adress is showing as

 


https://c.na7.visual.force.com/apex/pConsultantSummary?Alias=null

 

instead of null , i want to pass the exact alias in order to generate the report which is based on the alias.

 

i hope this will give u the clear picture.

aamDevaamDev

I understand. I currently use javascript in a output link value and it works just fine for me. With that said:

 

  1. Replace &colon; with an actual colon.
  2. I use eclipse and I noticed that if I just reclosed the outputlink tag and saved, it worked just fine. I'd suggest retrying.

 

Adriel

ali abdullahali abdullah

now the  below code is showing me the syntax error.

 

<apex:column headerValue="Consultant" value="{!item.theUser.Name}"/>
<apex:column headerValue="Consultant">
<apex:outputLink value="javascript&colon;AF_LoadReports('{!item.the​User.Alias}')">{!item.theUser.Alias}</apex:outputLink>
</apex:column>
<apex:column headerValue="Department" value="{!item.theUser.Division}"/>
<apex:column headerValue="Active Projects" value="{!item.noProjects}"/>
<apex:column headerValue="Active Tasks" value="{!item.noTasks}"/>
<apex:column headerValue="Last Login Date" value="{!item.theUser.LastLoginDate}"/>
</apex:pageBlockTable>
  </apex:PageBlockSection>

ali abdullahali abdullah

i just replaced & colon with actual colon but while pasting here its showing & colon again.

 

but in any case , i replaced with the colon in the actual VF page and its showing me the syntax error.

ali abdullahali abdullah

i tried <apex:outputText  command but still i am getting syntax error. below is the visual force page code.

 


<apex:column headerValue="Consultant">
<apex:outputText value="{!item.theUser.Name}"/>
</apex:column>
<apex:column headerValue="Consultant">
<apex:outputLink value="javascript&colon;AF_LoadReports('{!item.the​User.Alias}')">{!item.theUser.Alias}</apex:outputLink>
</apex:column>
<apex:column headerValue="Department">
<apex:outputText value="{!item.theUser.Division}"/>
</apex:column>
<apex:column headerValue="Active Projects">
<apex:outputText value="{!item.noProjects}"/>
</apex:column>
<apex:column headerValue="Active Tasks">
<apex:outputText value="{!item.noTasks}"/>
</apex:column>
<apex:column headerValue="Last Login Date">
<apex:outputText value="{!item.theUser.LastLoginDate}"/>
</apex:column>


</apex:pageBlockTable>
  </apex:PageBlockSection>
  
   
       
     </apex:pageBlock>
    

   
  </apex:form>
  </apex:page>

ali abdullahali abdullah

thanks Dev for your support.

 

anyways there i resolved the syntax issue and added the code as u suggested , but its still showing Null value in the webadress.

 

in addition to that this code is ading one more column with the name of consultant and retriving aliases. but still when i click on any alias its showing me null value on the adress.

aamDevaamDev

Hi Ali,

 

I'm glad you were able to resolve the syntax error. I apologize if I misunderstood earlier, but the sample code I gave you will create a new column with the Aliases. If you want the name to be seen but the alias to be passed to the webaddress, replace the alias field within the outputlink tag with the name field instead. I'm sorry if I assumed too much with respect to your vf knowledge.

 

As for your web address not showing the value you want, I'd have to think that your javascript is incorrect. Try replacing the entire the javacript link to a regular url and removing it from your controller class.

 

Instead of :

 

<apex:column headerValue="Consultant">
<apex:outputLink value="javascript&colon;AF_LoadReports('{!item.the​User.Alias}')">{!item.theUser.Alias}</apex:outputLink>
</apex:column>

 

put:

 

<apex:column headerValue="Consultant">
<apex:outputLink value="https://c.na7.visual.force.com/apex/pConsultantSummary?Alias={!item.the​User.Alias}">{!item.theUser.Alias}</apex:outputLink>
</apex:column>

 

This should work.

This was selected as the best answer
ali abdullahali abdullah

thanks Dev for ur help :)

 

it worked successfully :)