You need to sign in to do that
Don't have an account?
Michael Benson 4
How do I pass parameter correctly to another Website page using a function that redirects to the other page directly?
I have a webpage(vsualforce page) that has a search. I wish to pass the search text, and another variable set by the called function which redirect to a new webpage. On that new second webpage these parameters are used to list knowledge base articles.
My controller has the below:
public String searchstring { get; set; }
public String searchparm { get; set; }
public pagereference Results_PRO_Pageredirect_new() {
PageReference pageRef = new PageReference('http://sctest-transact-tech.cs51.force.com/SearchResultsPage');
searchparm = 'Knowledge_Categories:AccuDate_Pro';
refreshSearchResult();
pageRef.setRedirect(false);
return pageRef;
}
The first page (search page) has this for input with search button:
<apex:form >
<apex:inputText value="{!searchstring}" id="theSearchstring" maxlength="100" size="110" onkeypress="if (event.keyCode == 13) {refreshSearchResult();return false;} "/>
<apex:commandButton id="submitButton" style="width:40" action="{!Results_PRO_Pageredirect_new}" value="Search" />
<apex:messages />
</apex:form>
And the SearchResultsPage (visualforce page) I'm trying to pass to is:
<apex:page controller="myFSTController" standardStylesheets="false" sidebar="false" title="KB Search" showheader="false" doctype="HTML-5.0">
<!-- Search Results-->
<apex:panelGroup id="theSearchResults" >
<apex:panelGrid width="100%">
<table width="99%">
<tr>
<th width="33%">Title</th>
<th width="33%">Article Type</th>
<th width="33%">Summary</th>
</tr>
</table>
<knowledge:articleList articleVar="article" categories="{!searchparm}" Keyword="{!searchstring}" pageNumber="{!currentPageNumber}" hasMoreVar="false" pageSize="10">
<table width="99%">
<tr>
<td width="33%">
<apex:outputLink target="_blank" value="{!URLFOR($Action.KnowledgeArticle.View,article.id,['popup' = 'true'])}">{!article.title}</apex:outputLink>
</td>
<td width="33%"><apex:outputText >{!article.articleTypeLabel}</apex:outputText></td>
<td width="33%"><apex:outputText >{!article.abstract}</apex:outputText></td>
</tr>
</table>
</knowledge:articleList>
</apex:panelGrid>
<apex:form >
The parameters are not being passed, and I get results as if the parameters are blank.
What am I doing wrong?
Thanks!
Michael
My controller has the below:
public String searchstring { get; set; }
public String searchparm { get; set; }
public pagereference Results_PRO_Pageredirect_new() {
PageReference pageRef = new PageReference('http://sctest-transact-tech.cs51.force.com/SearchResultsPage');
searchparm = 'Knowledge_Categories:AccuDate_Pro';
refreshSearchResult();
pageRef.setRedirect(false);
return pageRef;
}
The first page (search page) has this for input with search button:
<apex:form >
<apex:inputText value="{!searchstring}" id="theSearchstring" maxlength="100" size="110" onkeypress="if (event.keyCode == 13) {refreshSearchResult();return false;} "/>
<apex:commandButton id="submitButton" style="width:40" action="{!Results_PRO_Pageredirect_new}" value="Search" />
<apex:messages />
</apex:form>
And the SearchResultsPage (visualforce page) I'm trying to pass to is:
<apex:page controller="myFSTController" standardStylesheets="false" sidebar="false" title="KB Search" showheader="false" doctype="HTML-5.0">
<!-- Search Results-->
<apex:panelGroup id="theSearchResults" >
<apex:panelGrid width="100%">
<table width="99%">
<tr>
<th width="33%">Title</th>
<th width="33%">Article Type</th>
<th width="33%">Summary</th>
</tr>
</table>
<knowledge:articleList articleVar="article" categories="{!searchparm}" Keyword="{!searchstring}" pageNumber="{!currentPageNumber}" hasMoreVar="false" pageSize="10">
<table width="99%">
<tr>
<td width="33%">
<apex:outputLink target="_blank" value="{!URLFOR($Action.KnowledgeArticle.View,article.id,['popup' = 'true'])}">{!article.title}</apex:outputLink>
</td>
<td width="33%"><apex:outputText >{!article.articleTypeLabel}</apex:outputText></td>
<td width="33%"><apex:outputText >{!article.abstract}</apex:outputText></td>
</tr>
</table>
</knowledge:articleList>
</apex:panelGrid>
<apex:form >
The parameters are not being passed, and I get results as if the parameters are blank.
What am I doing wrong?
Thanks!
Michael
Can you let us know that Controller of both the page are same or not? Because if the URL of the PageReference object is set to a website outside of the salesforce.com domain, or to a page with a different controller or controller extension, the redirect always occurs, regardless of whether the redirect attribute is set to true or false.
VF Page FSTPRo_v3:
<apex:page controller="myFSTController" standardStylesheets="false" sidebar="false" title="KB Search" showheader="false" doctype="HTML-5.0">
<html>
<head>
<style>
</style>
</head>
<body>
<!--Logo and Header-->
AccuDate PRO
<!--Logo and Header-->
<!-- Search Bar section -->
<apex:form >
<apex:inputText value="{!searchstring}" id="theSearchstring" maxlength="100" size="110" onkeypress="if (event.keyCode == 13) {refreshSearchResult();return false;} "/>
<apex:commandButton id="submitButton" style="width:40" action="{!Results_PRO_Pageredirect_new}" value="Search" />
<apex:messages />
</apex:form>
<!-- Search Bar section -->
<!--Featured Content section -->
Featured Content
<knowledge:articleList articleVar="article" categories="Knowledge_Categories:AccuDate_PRO, Featured_Content:Yes" pageSize="10">
<li>
<apex:outputLink target="_self" value="{!URLFOR($Action.KnowledgeArticle.View, article.id, ['popup' = 'true'])}">{!article.title}</apex:outputLink>
</li>
</knowledge:articleList>
<!-- Featured Content section -->
<!-- Video Tutorial Content section -->
Video Tutorials
<knowledge:articleList articleVar="article" categories="Knowledge_Categories:AccuDate_PRO" articleTypes="Video_Tutorial__kav" pageSize="10">
<li>
<apex:outputLink target="_self" value="{!URLFOR($Action.KnowledgeArticle.View, article.id, ['popup' = 'true'])}">{!article.title}</apex:outputLink>
</li>
</knowledge:articleList>
<!-- Video Tutorial Content section -->
<!-- User Guides Content section-->
User Guides
<knowledge:articleList articleVar="article" categories="Knowledge_Categories:AccuDate_PRO" articleTypes="User_Guide__kav" pageSize="10">
<li>
<apex:outputLink target="_self" value="{!URLFOR($Action.KnowledgeArticle.View, article.id, ['popup' = 'true'])}">{!article.title}</apex:outputLink>
</li>
</knowledge:articleList>
<!-- User Guides Content section-->
<!-- Warranty & Repair Content section-->
Warranty
<knowledge:articleList articleVar="article" categories="Knowledge_Categories:AccuDate_PRO" articleTypes="Warranty_Information__kav" pageSize="10">
<li>
<apex:outputLink target="_self" value="{!URLFOR($Action.KnowledgeArticle.View, article.id, ['popup' = 'true'])}">{!article.title}</apex:outputLink>
</li>
</knowledge:articleList>
<!-- Warranty & Repair Content section-->
</body>
</html>
</apex:page>
:END VF Page FSTPRo_v3
VF Page SearchResultsPage:
<apex:page controller="myFSTController" standardStylesheets="false" sidebar="false" title="KB Search" showheader="false" doctype="HTML-5.0">
<!-- Search Results-->
<apex:panelGroup id="theSearchResults" >
<apex:panelGrid width="100%">
<table width="99%">
<tr>
<th width="33%">Title</th>
<th width="33%">Article Type</th>
<th width="33%">Summary</th>
</tr>
</table>
<knowledge:articleList articleVar="article" categories="{!searchparm}" Keyword="{!searchstring}" pageNumber="{!currentPageNumber}" hasMoreVar="false" pageSize="10">
<table width="99%">
<tr>
<td width="33%">
<apex:outputLink target="_blank" value="{!URLFOR($Action.KnowledgeArticle.View,article.id,['popup' = 'true'])}">{!article.title}</apex:outputLink>
</td>
<td width="33%"><apex:outputText >{!article.articleTypeLabel}</apex:outputText></td>
<td width="33%"><apex:outputText >{!article.abstract}</apex:outputText></td>
</tr>
</table>
</knowledge:articleList>
</apex:panelGrid>
<apex:form >
<!-- Prev and Next buttons for multiply page results-->
<apex:panelGrid columns="2">
<apex:commandLink action="{!previous}" value="Previous" style="{!IF(prevRequired =true,'display:block','display:none')}" reRender="theSearchResults"/>
<apex:commandLink action="{!next}" value="Next" style="{!IF(nextRequired =true,'display:block','display:none')}" reRender="theSearchResults"/>
</apex:panelGrid>
<apex:actionFunction action="{!refreshSearchResult}" name="refreshSearchResult" rerender="theSearchResults" >
</apex:actionFunction>
</apex:form>
</apex:panelGroup>
</apex:page>
:END VF Page Search Results Page
Controller myFSTController:
public class myFSTController {
//Page Size
private Static Final Integer PAGE_NUMBER = 10;
//Keeps track of current page & max size of article list
Integer currentPage = 1;
Integer maxSize = 1;
//Search String used in ArticleList tag
public String searchstring { get; set; }
public String searchparm { get; set; }
//Is new List reqd
private boolean isRefRequired = true;
public myFSTController() {
//String qryString = 'SELECT Id, title, UrlName, LastPublishedDate,LastModifiedById FROM KnowledgeArticleVersion WHERE (PublishStatus = \'online\' and Language = \'en_US\')';
//List<KnowledgeArticleVersion> articleList= Database.query(qryString);
//maxSize = articleList.size() ;
}
// Action call when the new list needs to be fetched
public PageReference refreshSearchResult() {
maxSize = currentPage = 1;
return null;
}
// Returns whether we need to see previous button or not
public boolean getPrevRequired() {
return currentPage > 1;
}
// Returns whether we need to see next button or not
public boolean getNextRequired() {
return currentPage * PAGE_NUMBER < maxSize;
}
//Returns current page number
public Decimal getCurrentPageNumber() {
return this.currentPage;
}
//action for next click
public PageReference next() {
if(maxSize > this.currentPage * PAGE_NUMBER) {
this.currentPage = this.currentPage + 1;
}
return null;
}
//action for previous click
public PageReference previous() {
if(this.currentPage > 1)
this.currentPage = this.currentPage - 1;
return null;
}
//public PageReference SubmitSearch9700() {
// PageReference prToNavigate = null;
// getCurrentPageNumber();
// getPrevRequired();
// getNextRequired();
// searchparm = 'Knowledge_Categories:AccuDate_9700';
// refreshSearchResult();
// prToNavigate = Page.SearchResultsPage;
// return prToNavigate;
// }
//public PageReference SubmitSearchPro() {
// PageReference prToNavigate = null;
// getCurrentPageNumber();
// getPrevRequired();
// getNextRequired();
// searchparm = 'Knowledge_Categories:AccuDate_Pro';
// prToNavigate = Page.SearchResultsPage;
// return prToNavigate;
// }
public pagereference Results_PRO_Pageredirect_new() {
PageReference pageRef = new PageReference('http://sctest-transact-tech.cs51.force.com/SearchResultsPage');
getCurrentPageNumber();
getPrevRequired();
getNextRequired();
searchparm = 'Knowledge_Categories:AccuDate_Pro';
refreshSearchResult();
pageRef.setRedirect(false);
return pageRef;
}
public pagereference Results_9700_Pageredirect_new() {
PageReference pageRef = new PageReference('http://sctest-transact-tech.cs51.force.com/SearchResultsPage');
getCurrentPageNumber();
getPrevRequired();
getNextRequired();
searchparm = 'Knowledge_Categories:AccuDate_9700';
refreshSearchResult();
pageRef.setRedirect(true);
return pageRef;
}
}
:END VF Page Search Results Page
Thank you for your help!
Michael
You can close this question. I was using the Sites incorrectly. I was mistakenly creating a site for each vfpage. I am now using correctly and the parameters are passing as expected.
thank you anyway for your help,
Michael