0

I created VF page which displays top 10 drivers based on thier driving efficiency(Soql query).

when the particular driver in the list clicks HOW?( To tell how they achieved that position) button a pop up box opens with text area(options:Submit,Cancel)...

After typing message in that text area driver will submit.

The problem is:This message should be stored in particular driver contact.How to get particular driver contact id who has clicked HOW? button and perform update operation.

Here is my VF page:

<apex:page sidebar="false"  controller="Leaderclass">
<apex:form >
<apex:pageBlock title="Leader Board" >
<style>
body .bPageBlock .pbBody .Grey .pbSubheader{
background-color:#c0c0c0;
}
</style>
<style type="text/css">
.customPopup {
background-color: white;
border-style: solid;
border-width: 2px;
left: 40%;
padding: 10px;
position: absolute;
z-index: 9999;
/* These are the 3 css properties you will need to tweak so the pop 
up displays in the center of the screen. First set the width. Then set 
margin-left to negative half of what the width is. You can also add 
the height property for a fixed size pop up.*/
width: 500px;
top: 20%;
}

.disabledTextBox {
background-color: white;
border: 1px solid;
color: black;
cursor: default;
width: 90px;
display: table;
padding: 2px 1px;
text-align:right;
}   

.closeButton {
float: right;
}
</style>

<apex:outputPanel styleClass="Grey " layout="block">
<apex:pageBlockSection title="Top 10 Leaders"  >
<apex:pageBlockTable value="{!wrapper}"   var="a" id="table" >
<apex:column headervalue="DriverName" >{!a.Dname}</apex:column>
<apex:column headerValue="Average Efficiency" >{!a.Deffi}</apex:column>
<apex:column headervalue="Badge" > 
<apex:image value="{!If((a.Deffi >0 && a.Deffi <4), $Resource.Diamond, 
If((a.Deffi >= 4 && a.Deffi <5), $Resource.Platinum,
If((a.Deffi >= 5 && a.Deffi <6), $Resource.Gold,
If((a.Deffi >= 6 && a.Deffi <8), $Resource.silver,
If((a.Deffi >8), $Resource.StopDriving,
$Resource.StartDriving)))))}" width="50" height="50" />
</apex:column>
<apex:column headerValue="User Stories">
<apex:commandButton value="HOW?" action="{!showPopup}" rerender="popup" status="status"  onmouseover="openPopup();" /></apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:outputPanel>

<apex:outputPanel id="popup">
<apex:outputPanel id="popInnerOutputPnl" styleClass="customPopup" layout="block" rendered="{!displayPopUp}">
<apex:commandButton value="Submit" action="{!redirectPopup}" styleClass="closeButton" rerender="popup">
</apex:commandButton>
<apex:pageblockSection >                         
<apex:pageblockSectionItem >
<apex:outputLabel value="Story" for="story"></apex:outputLabel>
<apex:inputTextArea cols="60" rows="3" />
</apex:pageblockSectionItem>
</apex:pageblockSection>
<apex:commandButton value="Cancel" title="Close the popup" action="{!closePopup}" styleClass="closeButton" rerender="popup">
</apex:commandButton>
</apex:outputPanel>
</apex:outputPanel>

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

Apex Page:

public with sharing class Leaderclass{
public Leaderclass() {

}
public Leaderclass(ApexPages.StandardController controller) {
}
public String showPopup { get; set; }
public String Story{get;set;} // input text1 value  from vf
List<DriverEfficiency__c> e= new List<DriverEfficiency__c>();
List<AggregateResult> a=new List<AggregateResult>();
public List<wrapper> w= new List<wrapper>();
public List<wrapper> getwrapper() {
a= [select DriverContact__r.name Dname ,avg(Efficiency_Rating__c) from DriverEfficiency__c GROUP BY DriverContact__r.name order by avg(Efficiency_Rating__c) asc  limit 10];
for (AggregateResult SalesList : a) {
w.add(new wrapper(String.valueOf(SalesList.get('Dname')), Double.valueOf(SalesList.get('expr0'))));
}
return w;
}


// Wrapper Class Construction
public class wrapper{
public String Dname{get;set;}
public Double Deffi{get;set;}

// Wrapper class constructor
public wrapper(String Dname,Double Deffi){
this.Dname=Dname;
this.Deffi=Deffi;
}
}

public Boolean displayPopup {get;set;}
public void showPopup()
{
displayPopup = true;
}

public void closePopup() {
displayPopup = false;
}
private  contact myContact;
public PageReference redirectPopup()
{
displayPopup = false;
//PageReference p=new Pagereference('/'+'apex'+'/'+'Wrapper');
myContact = [SELECT Id, Name FROM contact
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
myContact.StoreImageUrl__c=Story;
update myContact;
return null;
//p.setRedirect(true);
//return p;
}
}

Please help me...Thanks in advance for your kindly help..

0

I think you can try this way:

<apex:pageBlockTable value="{!wrapper}"   var="a" id="table" >
...
    <apex:commandButton onclick="showPopup({!a.dId})" ...>
...
</apex:pageBlockTable>
...
<apex:actionFunction name="showPopup" action="{!showPopup}" rerender="popup" status="...">
    <apex:param name="driverId" assignTo="{!driverId}" value=""/>
</apex:actionFunction>

In controller you have to add property

public String driverId {get;set;}

And you can use this value in submit method. Also you need add dId (driver id, I think) in your wrapper and soql.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.