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
visulaforcevisulaforce 

how to pass object as parameter of command link

Hi,

In the code written below i do have one VF page. this page display list of documents. Each row displayed with three command link for Edit, Delete and View the doc. on action of Edit, View and Delete command link method will get called. I have defined these editDoc, deleteDoc and viewDoc methods in "ViewDocumentControllerExt" controller class. I hav 2 issues with that.

1) when i click on any of commandlink same page is getting refreshed and controlller is not getting transfered to the page in pageRef variable and i dont know wether method is getting called or not cos i no debug is getting displayed.

2) I wanna pass a object as parameter of command link and wanna get this object value in Apex class . how to do that.

Pls provide me solution asap.



<apex:page action="{!loginDocMall}" standardController="Opportunity" extensions="ViewDocumentControllerExt" tabstyle="Opportunity">
<apex:form >
<apex:pageBlock title="Document">
<apex:dataTable value="{!propertyList}" var="docProperty" columns="9">
<apex:column >
<apex:commandLink value="Edit" action={!editDoc}>
<apex:param name="docId" value="{!docProperty.docId}"/>
</apex:commandLink >
</apex:column>
<apex:column >
<apex:commandLink value="View" action="{!viewDoc}">
<apex:param name="docId" value="{!docProperty.docId}"/>
</apex:commandLink>
</apex:column>
<apex:column >
<apex:commandLink action="{!deleteDoc}" value="Del">
<apex:param name="docId" value="{!docProperty.docId}"/>
</apex:commandLink>
</apex:column>
<apex:column value="{!docProperty.category}"/>
<apex:column >
<apex:commandLink value="{!docProperty.title}" />
</apex:column>
<apex:column value="{!docProperty.size}"/>
<apex:column value="{!docProperty.subject}"/>
<apex:column value="{!docProperty.keywords}"/>
<apex:column value="{!docProperty.lastModified}"/>
</apex:dataTable>
</apex:pageBlock>
</apex:form>
</apex:page>




public class ViewDocumentControllerExt
{
private static String sessionId = null;
private final Opportunity opportunity;
private static List<DocProperty> propertyList = new List<DocProperty>();

// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller.
public ViewDocumentControllerExt(ApexPages.StandardController stdController) {
this.opportunity = (Opportunity)stdController.getRecord();
}

public List<DocProperty> getPropertyList()
{
return propertyList;
}


public String getSessionId()
{
return sessionId;
}

.........
some more methods here
.........

public PageReference editDoc()
{
String id = System.currentPageReference().getParameters().get('docId');
PageReference pageRef = new PageReference('/apex/docEditPage');
pageRef.setRedirect(true);
return pageRef;
}

public PageReference viewDoc()
{
System.debug('inside viewDoc method');
PageReference pageRef = new PageReference('/apex/docViewPage');
pageRef.setRedirect(true);
return pageRef;
}

public PageReference deleteDoc()
{
System.debug('inside deleteDoc method');
String id = System.currentPageReference().getParameters().get('docId');
PageReference pageRef = new PageReference('/apex/docDeletePage');
pageRef.setRedirect(true);
return pageRef;
}

}

dchasmandchasman
This is a case where using <apex:commandLink> and action methods is overkill - <apex:outputLink> would be a much better choice. Also when you really do need an action method and need to refer to a page you should be using the built in Page collection, e.g. instead of
PageReference pageRef = new PageReference('/apex/docEditPage');

use

Page.docEditPage
Back to your specific problem - something like this (NOTE: some content omitted for brevity) would be much more direct and will also perform better (no need to post back to the server and invoke any action methods):

Code:
<apex:page action="{!loginDocMall}" standardController="Opportunity">
<apex:pageBlock title="Document">
<apex:dataTable value="{!propertyList}" var="docProperty" columns="9">
<apex:column>
<apex:outputLink value="{!urlFor($Page.docEditPage, null, [docid = docProperty.docId])}">Edit</apex:outputLink>
</apex:column>
<apex:column>
<apex:outputLink value="{!urlFor($Page.docViewPage, null, [docid = docProperty.docId])}">View</apex:outputLink>
</apex:column>
<apex:column>
<apex:outputLink value="{!urlFor($Page.docDeletePage, null, [docid = docProperty.docId])}">Delete</apex:outputLink>
</apex:column>
<apex:column value="{!docProperty.size}"/>
<apex:column value="{!docProperty.subject}"/>
<apex:column value="{!docProperty.keywords}"/>
<apex:column value="{!docProperty.lastModified}"/>
</apex:dataTable>
</apex:pageBlock>
</apex:page>

 


BTW can you please use SRC blocks to contain code in your posts and also post indented VF markup - both make it much easier for folks to read and understand your markup which ultimately helps you get your questions answered faster - thanks!


Message Edited by dchasman on 06-15-2008 10:43 AM
visulaforcevisulaforce
Hi,

Thnx for reply . But problem is still there.

1)I wanna pass some sensitive information sessionId and object. If i use "outputLink" tag  then  this  will  appened in url query string n will be visible.

2) When i am passing object as parameter in outputLink tag n trying to get the same in Apex class it's giving me error like


Error: Compile Error: Incompatible types since an instance of String is never an instance of lzhang.DocProperty at line 15 column 22

in expression in code below:

(DocProperty) System.currentPageReference().getParameters().get('docProp');


Code:
public class EditDocument
{

private Opportunity  opportunity = null;

public EditDocument(ApexPages.StandardController stdController) {
this.opportunity = (Opportunity)stdController.getRecord();
}

public void init()
{
    System.debug('inside init of EditDocument');
    String sessionId = System.currentPageReference().getParameters().get('sessionid');
    String docProp = (DocProperty) System.currentPageReference().getParameters().get('docProp');
    System.debug('sessionId :'+sessionId);    
    System.debug('docProp :'+docProp.getDocId()); 
}
}

 
Code:
public class DocProperty
{

private String docId = null;
private String category = null;
private String title = null;
private String size = null;
private String subject = null;
private String keywords = null;
private String lastModified = null;

public DocProperty() {}

public DocProperty(String docId, String category, String title, String size, String subject,String keywords, String lastModified)
{
this.docId = docId;
this.category = category;
this.title = title;
this.size = size;
this.subject = subject;
this.keywords = keywords;
this.lastModified = lastModified;
}

public String getDocId()
{
    return docId;
}
public String getCategory()
{
    return category;
}
public String getTitle()
{
    return title;
}
public String getSize()
{
    return size;
}
public String getSubject()
{
    return subject;
}
public String getKeywords()
{
    return keywords;
}
public String getLastModified()
{
    return lastModified;
}

public void setDocId(String docId)
{
    this.docId = docId;
}
public void setCategory(String category)
{
    this.category = category;
}
public void setTitle(String title)
{
    this.title = title;
}
public void setSize()
{
    this.size = size;
}
public void setSubject(String subject)
{
    this.subject = subject;
}
public void setKeywords(String keywords)
{
    this.keywords = keywords;
}
public void setLastModified(String lastModified)
{
    this.lastModified = lastModified;
}
}

 


Code:
<apex:page action="{!loginDocMall}" standardController="Opportunity" extensions="ViewDocumentControllerExt" tabstyle="Opportunity">
<apex:form >
<apex:pageBlock title="Document">
<apex:dataTable value="{!propertyList}" var="docProperty" columns="9">
<apex:column >
    <apex:outputLink value="{!urlFor($Page.docEditPage, null, [sessionid = sessionId, docProp = docProperty])}">Edit</apex:outputLink>
</apex:column>
<apex:column >
    <apex:outputLink value="{!urlFor($Page.docViewPage, null, [sessionid = sessionId, docProp = docProperty])}">View</apex:outputLink>
</apex:column>
<apex:column >
    <apex:outputLink value="{!urlFor($Page.docDeletePage, null, [sessionid = sessionId, docProp = docProperty])}">Delete</apex:outputLink>
</apex:column>
<apex:column value="{!docProperty.category}"/>
<apex:column >
<apex:commandLink value="{!docProperty.title}">
<apex:param name="docId" value="{!docProperty.docId}"/>
</apex:commandLink>
</apex:column>
<apex:column value="{!docProperty.size}"/>
<apex:column value="{!docProperty.subject}"/>
<apex:column value="{!docProperty.keywords}"/>
<apex:column value="{!docProperty.lastModified}"/>
</apex:dataTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 



lopezclopezc
Hi!

I am trying to do something similiar.. well, I have the list of contacts in a new tap. I would like to view the details of each contact when clicking on the name.. however, I don't want to load a new page and staring to a blank browser during the process.. I would like to display the details in the same tap (same funtionality as the Contact tap) so just the content of the tap should change... do you know how to do that? here is my code..

Code:
<apex:page controller="dataListCon" tabStyle="Contact" showheader="true">
<apex:sectionHeader title="Client Accounts" subtitle="Home" help="javascript:openPopupFocusEscapePounds('/help/doc/user_ed.jsp—loc=help&target=contacts_overview.htm&section=Contacts&showSplash=true', 'Help', 700, 600, 'width=700,height=600,resizable=yes,toolbar=yes,status=no,scrollbars=yes,menubar=yes,directories=no,location=no,dependant=no', false, false);" />

 <apex:form >
<apex:pageBlock title="Recent Client Accounts">
    <apex:pageBlockTable value="{!contacts}" var="contact" cellPadding="4" border="0" rowClasses="dataRow" headerClass="headerRow"  footerClass="pShowMore">
        <apex:column width="500px">
                    <apex:facet name="header">Name</apex:facet>
                          <apex:outputLink value="{!showDetails}">
                              <apex:outputText value="{!contact.lastname}"/>
                          </apex:outputLink >
        </apex:column>
        <apex:column width="400px">
                  <apex:facet name="header">Account</apex:facet>
                  <apex:outputLink value="/{!contact.AccountId}" >
                           <apex:outputText value="{!contact.account.name}"/>
                   </apex:outputLink>           
        </apex:column>
        <apex:column width="400px">
                  <apex:facet name="header">Phone</apex:facet>
                         {!contact.phone}
        </apex:column>
       <apex:facet name="footer">
            <apex:commandLink action="{!lookMore}" value="Show 10 items" id="theCommandLink"/>            
        </apex:facet>
    </apex:pageBlockTable>
</apex:pageBlock>       
   </apex:form>

</apex:page>

 
My question is how should I implement the following function?
showDetails