You need to sign in to do that
Don't have an account?
Issue with Apex:outputlink and forced click
Problem:
I have a search field in the case view that needs to search and redirect to a 'full search' page when a users hits enter in the field.
The enter part isn't an issue, the issue is that since this is inside the case layout page, I can not use a commandbutton/ commandlink since if I do it would redirect to the page but it will show inline=1 in the URL and thus treat it as an inline page and hide the header/sidebar. If I use the output link it will go to the page and not add inline=1 in the URL and show the header. BUT if I use the outputlink, when I force a click on the button, it performs the method, but not the redirect, so it just sits there.
In my method I put in system.debug and watched the system log, it showed that it did reach the method and did what was in it, but once it got to the return part with the new page reference, it just didn't do it. If I were to physically click the button instead of having the event listener do a jQuery .click() it will refresh to the new page.
To make sure it was nothing on the page that was wrong, or to see if it was just an outputlink, I did a test page with just simple methods and nothing in it but the required for testing. First i tested the commandlink/commandbutton:
<apex:page controller="LinkOnClickCon"> <apex:includeScript value="{!URLFOR($Resource.knowledgeTicket, '/jquery-1.4.2.min.js')}"/> <script type="text/javascript" language="JavaScript"> jQuery.noConflict(); jQuery(document).ready(function() { jQuery('.searchtoolstextbox').keypress(function(e) { code = e.keyCode ? e.keyCode : e.which; //alert(code.toString()); if (code.toString() == 13){ e.preventDefault(); if(jQuery('.searchtoolstextbox').val().length >= 3){ jQuery('.fullsearchbutton').click(); } } }); }); </script> <apex:form id="form"> <apex:inputText id="kbsearchtext" value="{!userkeywords}" styleClass="searchtoolstextbox" /> <apex:actionRegion id="FullSearchActionRegion"> <apex:commandlink id="btnFullSearch1" styleClass="btn fullsearchbutton" action="{!getactionTwo}" onclick="alert('I was clicked');" value="Full Search"> <apex:actionSupport event="onClick" action="{!getactionTwo}" status="workstatus" /> </apex:commandlink> </apex:actionRegion> <apex:actionStatus id="workstatus" startText="working..." stopText="" /> </apex:form> </apex:page>
and controller:
public with sharing class LinkOnClickCon { public string userkeywords{get; set;} Public pagereference getactionTwo(){ system.debug('\n ACTION Two METHOD userkeywords: '+userkeywords+'\n The enter key was clicked and so this should now be called.'); string kywrds = userKeywords; if(kywrds == NULL || kywrds == ''){kywrds = 'keyword';} kywrds = EncodingUtil.urlEncode(kywrds, 'UTF-8'); system.debug('\n\n METHOD getactionTwo() - keywords: ' + kywrds + '\n \n'); PageReference ref = new PageReference('/apex/knowledge?keywords=' + kywrds ); system.debug('\n\n METHOD getactionTwo() - pageRef: ' + ref.getUrl() + '\n \n'); ref.setRedirect(true); return ref; } }
With the commandlink/command button it works, it redirects to the new page (but like I said earlier, if I use this in the case layout it will redirect with a URL pram of inline=1 witch is bad).
The system log:
19.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO 11:51:36.499 (18334000)|EXECUTION_STARTED 11:51:36.499 (18404000)|CODE_UNIT_STARTED|[EXTERNAL]|066Q00000008nD9|VF: /apex/linkonclick 11:51:36.499 (18701000)|CODE_UNIT_STARTED|[EXTERNAL]|01pQ0000000DK56|LinkOnClickCon get(userkeywords) 11:51:36.499 (18733000)|SYSTEM_MODE_ENTER|APEX_FULL 11:51:36.500 (19058000)|CODE_UNIT_STARTED|[EXTERNAL]|01pQ0000000DK56|userkeywords 11:51:36.500 (19090000)|CODE_UNIT_FINISHED|userkeywords 11:51:36.500 (19126000)|CODE_UNIT_FINISHED|LinkOnClickCon get(userkeywords) 11:51:36.501 (20273000)|CODE_UNIT_STARTED|[EXTERNAL]|LinkOnClickCon set(userkeywords,offline) 11:51:36.501 (20308000)|SYSTEM_MODE_ENTER|APEX_FULL 11:51:36.501 (20603000)|CODE_UNIT_STARTED|[EXTERNAL]|LinkOnClickCon set(userkeywords,offline) 11:51:36.501 (20648000)|METHOD_ENTRY|[1]|01pQ0000000DK56|LinkOnClickCon.LinkOnClickCon() 11:51:36.501 (20687000)|STATEMENT_EXECUTE|[1]|Static initialization: LinkOnClickCon 11:51:36.501 (20716000)|SYSTEM_MODE_ENTER|APEX_SHARING_HONORED 11:51:36.501 (20755000)|STATEMENT_EXECUTE|[1]|ThisBlock with 1 statement 11:51:36.501 (20787000)|SYSTEM_MODE_EXIT|APEX_SHARING_HONORED 11:51:36.501 (20812000)|METHOD_EXIT|[1]|LinkOnClickCon 11:51:36.501 (20856000)|CODE_UNIT_FINISHED|LinkOnClickCon set(userkeywords,offline) 11:51:36.501 (20883000)|CODE_UNIT_FINISHED|LinkOnClickCon set(userkeywords,offline) 11:51:36.502 (21653000)|CODE_UNIT_STARTED|[EXTERNAL]|01pQ0000000DK56|LinkOnClickCon invoke(getactionTwo) 11:51:36.502 (21758000)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this|{"userkeywords":"offline"}|0x1efb058 11:51:36.502 (21795000)|SYSTEM_MODE_ENTER|APEX_SHARING_HONORED 11:51:36.502 (21828000)|STATEMENT_EXECUTE|[5]|Block with 9 statements 11:51:36.502 (21888000)|STATEMENT_EXECUTE|[6]|system.debug(String) 11:51:36.502 (21924000)|METHOD_ENTRY|[6]|System.debug(ANY) 11:51:36.502 (21969000)|HEAP_ALLOCATE|[6]|Bytes:41 11:51:36.503 (22010000)|HEAP_ALLOCATE|[6]|Bytes:102 11:51:36.503 (22039000)|USER_DEBUG|[6]|DEBUG| ACTION Two METHOD userkeywords: offline The enter key was clicked and so this should now be called. 11:51:36.503 (22072000)|METHOD_EXIT|[6]|System.debug(ANY) 11:51:36.503 (22127000)|STATEMENT_EXECUTE|[7]|DeclareVar: String kywrds 11:51:36.503 (22157000)|VARIABLE_SCOPE_BEGIN|[7]|kywrds|String|false 11:51:36.503 (22201000)|VARIABLE_ASSIGNMENT|[7]|kywrds|"offline" 11:51:36.503 (22232000)|VARIABLE_ASSIGNMENT|[7]|kywrds|"offline" 11:51:36.503 (22264000)|STATEMENT_EXECUTE|[8]|Condition 11:51:36.503 (22377000)|STATEMENT_EXECUTE|[8]|Condition 11:51:36.503 (22432000)|STATEMENT_EXECUTE|[9]|String kywrds <= MethodInvocation 11:51:36.503 (22476000)|METHOD_ENTRY|[9]|system.EncodingUtil.urlEncode(String, String) 11:51:36.503 (22524000)|STATEMENT_EXECUTE|[1]|Static initialization: system.EncodingUtil 11:51:36.503 (22571000)|STATEMENT_EXECUTE|[1]|ThisBlock with 1 statement 11:51:36.503 (22607000)|VARIABLE_SCOPE_BEGIN|[9]|s|String|false 11:51:36.503 (22648000)|VARIABLE_ASSIGNMENT|[9]|s|"offline" 11:51:36.503 (22675000)|VARIABLE_SCOPE_BEGIN|[9]|enc|String|false 11:51:36.503 (22711000)|VARIABLE_ASSIGNMENT|[9]|enc|"UTF-8" 11:51:36.503 (22859000)|METHOD_EXIT|[9]|system.EncodingUtil.urlEncode(String, String) 11:51:36.503 (22899000)|VARIABLE_ASSIGNMENT|[9]|kywrds|"offline" 11:51:36.503 (22929000)|VARIABLE_ASSIGNMENT|[9]|kywrds|"offline" 11:51:36.503 (22978000)|STATEMENT_EXECUTE|[10]|system.debug(String) 11:51:36.504 (23023000)|METHOD_ENTRY|[10]|System.debug(ANY) 11:51:36.504 (23060000)|HEAP_ALLOCATE|[10]|Bytes:44 11:51:36.504 (23089000)|HEAP_ALLOCATE|[10]|Bytes:47 11:51:36.504 (23115000)|USER_DEBUG|[10]|DEBUG| METHOD getactionTwo() - keywords: offline 11:51:36.504 (23145000)|METHOD_EXIT|[10]|System.debug(ANY) 11:51:36.504 (23197000)|STATEMENT_EXECUTE|[11]|DeclareVar: System.PageReference ref 11:51:36.504 (23226000)|VARIABLE_SCOPE_BEGIN|[11]|ref|PageReference|true 11:51:36.504 (23267000)|HEAP_ALLOCATE|[11]|Bytes:32 11:51:36.504 (23358000)|HEAP_ALLOCATE|[11]|Bytes:38 11:51:36.504 (23432000)|STATEMENT_EXECUTE|[12]|system.debug(String) 11:51:36.504 (23465000)|METHOD_ENTRY|[12]|System.debug(ANY) 11:51:36.504 (23503000)|METHOD_ENTRY|[12]|System.PageReference.getUrl() 11:51:36.504 (23558000)|METHOD_EXIT|[12]|System.PageReference.getUrl() 11:51:36.504 (23587000)|HEAP_ALLOCATE|[12]|Bytes:68 11:51:36.504 (23615000)|HEAP_ALLOCATE|[12]|Bytes:71 11:51:36.504 (23641000)|USER_DEBUG|[12]|DEBUG| METHOD getactionTwo() - pageRef: /apex/knowledge?keywords=offline 11:51:36.504 (23671000)|METHOD_EXIT|[12]|System.debug(ANY) 11:51:36.504 (23720000)|STATEMENT_EXECUTE|[13]|System.PageReference.setRedirect(Boolean) 11:51:36.504 (23754000)|METHOD_ENTRY|[13]|System.PageReference.setRedirect(Boolean) 11:51:36.504 (23791000)|METHOD_EXIT|[13]|System.PageReference.setRedirect(Boolean) 11:51:36.504 (23829000)|STATEMENT_EXECUTE|[14]|Return 11:51:36.504 (23871000)|SYSTEM_MODE_EXIT|APEX_SHARING_HONORED 11:51:36.504 (23923000)|CODE_UNIT_FINISHED|LinkOnClickCon invoke(getactionTwo) 11:51:36.504 (23999000)|VF_APEX_CALL|btnFullSearch1|{!getactionTwo}|PageReference:/apex/knowledge?keywords=offline 11:51:36.505|CUMULATIVE_LIMIT_USAGE 11:51:36.505|LIMIT_USAGE_FOR_NS|(default)| Number of SOQL queries: 0 out of 100 Number of query rows: 0 out of 10000 Number of SOSL queries: 0 out of 20 Number of DML statements: 0 out of 100 Number of DML rows: 0 out of 10000 Number of script statements: 9 out of 200000 Maximum heap size: 0 out of 3000000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 100 Number of record type describes: 0 out of 100 Number of child relationships describes: 0 out of 100 Number of picklist describes: 0 out of 100 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 10 Number of System.runAs() invocations: 0 out of 20 11:51:36.505|CUMULATIVE_LIMIT_USAGE_END 11:51:36.505 (24720000)|CODE_UNIT_FINISHED|VF: /apex/linkonclick 11:51:36.505 (24746000)|EXECUTION_FINISHED
But if I switch the page to use a outputlink instead:
<apex:form id="form"> <apex:inputText id="kbsearchtext" value="{!userkeywords}" styleClass="searchtoolstextbox" /> <apex:actionRegion id="FullSearchActionRegion"> <apex:outputlink id="btnFullSearch1" styleClass="btn fullsearchbutton" value="{!actionTwo}" onclick="alert('I was clicked');" > Full Search <apex:actionSupport event="onClick" action="{!getactionTwo}" status="workstatus" /> </apex:outputlink> </apex:actionRegion> <apex:actionStatus id="workstatus" startText="working..." stopText="" /> </apex:form>
And I hit enter in the field, nothing happens, it wont even see the string from the users input.
here is the system log:
19.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO 12:10:46.852 (23228000)|EXECUTION_STARTED 12:10:46.852 (23314000)|CODE_UNIT_STARTED|[EXTERNAL]|066Q00000008nD9|VF: /apex/linkonclick 12:10:46.853 (23528000)|CODE_UNIT_STARTED|[EXTERNAL]|01pQ0000000DK56|LinkOnClickCon <init> 12:10:46.853 (23563000)|SYSTEM_MODE_ENTER|APEX_FULL 12:10:46.853 (23676000)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this|{}|0x663ab9 12:10:46.853 (23716000)|STATEMENT_EXECUTE|[1]|Instance initialization: LinkOnClickCon 12:10:46.853 (23737000)|SYSTEM_MODE_ENTER|APEX_SHARING_HONORED 12:10:46.853 (23796000)|STATEMENT_EXECUTE|[3]|DeclarePropertyAccessor: public String userkeywords { get; set; } 12:10:46.853 (23821000)|VARIABLE_SCOPE_BEGIN|[3]|userkeywords|String|false 12:10:46.853 (23842000)|SYSTEM_MODE_EXIT|APEX_SHARING_HONORED 12:10:46.853 (23861000)|CODE_UNIT_FINISHED|LinkOnClickCon <init> 12:10:46.885 (55535000)|CODE_UNIT_STARTED|[EXTERNAL]|01pQ0000000DK56|LinkOnClickCon get(userkeywords) 12:10:46.885 (55570000)|SYSTEM_MODE_ENTER|APEX_FULL 12:10:46.885 (55720000)|CODE_UNIT_STARTED|[EXTERNAL]|01pQ0000000DK56|userkeywords 12:10:46.885 (55744000)|CODE_UNIT_FINISHED|userkeywords 12:10:46.885 (55766000)|CODE_UNIT_FINISHED|LinkOnClickCon get(userkeywords) 12:10:46.885 (56145000)|CODE_UNIT_STARTED|[EXTERNAL]|01pQ0000000DK56|LinkOnClickCon get(actionTwo) 12:10:46.885 (56171000)|SYSTEM_MODE_ENTER|APEX_FULL 12:10:46.886 (56736000)|CODE_UNIT_STARTED|[EXTERNAL]|01pQ0000000DK56|LinkOnClickCon invoke(getactionTwo) 12:10:46.886 (56798000)|STATEMENT_EXECUTE|[1]|Static initialization: LinkOnClickCon 12:10:46.886 (56826000)|SYSTEM_MODE_ENTER|APEX_SHARING_HONORED 12:10:46.886 (56857000)|STATEMENT_EXECUTE|[1]|ThisBlock with 1 statement 12:10:46.886 (56882000)|SYSTEM_MODE_EXIT|APEX_SHARING_HONORED 12:10:46.886 (56942000)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this|{}|0x663ab9 12:10:46.886 (56969000)|SYSTEM_MODE_ENTER|APEX_SHARING_HONORED 12:10:46.886 (56996000)|STATEMENT_EXECUTE|[5]|Block with 9 statements 12:10:46.886 (57043000)|STATEMENT_EXECUTE|[6]|system.debug(String) 12:10:46.886 (57073000)|METHOD_ENTRY|[6]|System.debug(ANY) 12:10:46.886 (57113000)|HEAP_ALLOCATE|[6]|Bytes:38 12:10:46.886 (57135000)|HEAP_ALLOCATE|[6]|Bytes:99 12:10:46.886 (57152000)|USER_DEBUG|[6]|DEBUG| ACTION Two METHOD userkeywords: null The enter key was clicked and so this should now be called. 12:10:46.886 (57173000)|METHOD_EXIT|[6]|System.debug(ANY) 12:10:46.886 (57215000)|STATEMENT_EXECUTE|[7]|DeclareVar: String kywrds 12:10:46.886 (57237000)|VARIABLE_SCOPE_BEGIN|[7]|kywrds|String|false 12:10:46.886 (57274000)|VARIABLE_ASSIGNMENT|[7]|kywrds|null 12:10:46.886 (57294000)|VARIABLE_ASSIGNMENT|[7]|kywrds|null 12:10:46.886 (57320000)|STATEMENT_EXECUTE|[8]|Condition 12:10:46.886 (57398000)|STATEMENT_EXECUTE|[8]|Block with 1 statement 12:10:46.887 (57452000)|STATEMENT_EXECUTE|[8]|String kywrds <= Literal 12:10:46.887 (57492000)|VARIABLE_ASSIGNMENT|[8]|kywrds|"keyword" 12:10:46.887 (57515000)|VARIABLE_ASSIGNMENT|[8]|kywrds|"keyword" 12:10:46.887 (57556000)|STATEMENT_EXECUTE|[9]|String kywrds <= MethodInvocation 12:10:46.887 (57592000)|METHOD_ENTRY|[9]|system.EncodingUtil.urlEncode(String, String) 12:10:46.887 (57628000)|STATEMENT_EXECUTE|[1]|Static initialization: system.EncodingUtil 12:10:46.887 (57659000)|STATEMENT_EXECUTE|[1]|ThisBlock with 1 statement 12:10:46.887 (57687000)|VARIABLE_SCOPE_BEGIN|[9]|s|String|false 12:10:46.887 (57720000)|VARIABLE_ASSIGNMENT|[9]|s|"keyword" 12:10:46.887 (57740000)|VARIABLE_SCOPE_BEGIN|[9]|enc|String|false 12:10:46.887 (57768000)|VARIABLE_ASSIGNMENT|[9]|enc|"UTF-8" 12:10:46.887 (57896000)|METHOD_EXIT|[9]|system.EncodingUtil.urlEncode(String, String) 12:10:46.887 (57928000)|VARIABLE_ASSIGNMENT|[9]|kywrds|"keyword" 12:10:46.887 (57951000)|VARIABLE_ASSIGNMENT|[9]|kywrds|"keyword" 12:10:46.887 (57988000)|STATEMENT_EXECUTE|[10]|system.debug(String) 12:10:46.887 (58011000)|METHOD_ENTRY|[10]|System.debug(ANY) 12:10:46.887 (58041000)|HEAP_ALLOCATE|[10]|Bytes:44 12:10:46.887 (58064000)|HEAP_ALLOCATE|[10]|Bytes:47 12:10:46.887 (58081000)|USER_DEBUG|[10]|DEBUG| METHOD getactionTwo() - keywords: keyword 12:10:46.887 (58102000)|METHOD_EXIT|[10]|System.debug(ANY) 12:10:46.887 (58142000)|STATEMENT_EXECUTE|[11]|DeclareVar: System.PageReference ref 12:10:46.887 (58164000)|VARIABLE_SCOPE_BEGIN|[11]|ref|PageReference|true 12:10:46.887 (58197000)|HEAP_ALLOCATE|[11]|Bytes:32 12:10:46.887 (58276000)|HEAP_ALLOCATE|[11]|Bytes:38 12:10:46.887 (58334000)|STATEMENT_EXECUTE|[12]|system.debug(String) 12:10:46.887 (58358000)|METHOD_ENTRY|[12]|System.debug(ANY) 12:10:46.887 (58386000)|METHOD_ENTRY|[12]|System.PageReference.getUrl() 12:10:46.888 (58436000)|METHOD_EXIT|[12]|System.PageReference.getUrl() 12:10:46.888 (58460000)|HEAP_ALLOCATE|[12]|Bytes:68 12:10:46.888 (58483000)|HEAP_ALLOCATE|[12]|Bytes:71 12:10:46.888 (58500000)|USER_DEBUG|[12]|DEBUG| METHOD getactionTwo() - pageRef: /apex/knowledge?keywords=keyword 12:10:46.888 (58521000)|METHOD_EXIT|[12]|System.debug(ANY) 12:10:46.888 (58557000)|STATEMENT_EXECUTE|[13]|System.PageReference.setRedirect(Boolean) 12:10:46.888 (58582000)|METHOD_ENTRY|[13]|System.PageReference.setRedirect(Boolean) 12:10:46.888 (58611000)|METHOD_EXIT|[13]|System.PageReference.setRedirect(Boolean) 12:10:46.888 (58641000)|STATEMENT_EXECUTE|[14]|Return 12:10:46.888 (58674000)|SYSTEM_MODE_EXIT|APEX_SHARING_HONORED 12:10:46.888 (58697000)|CODE_UNIT_FINISHED|LinkOnClickCon invoke(getactionTwo) 12:10:46.888 (58726000)|CODE_UNIT_FINISHED|LinkOnClickCon get(actionTwo) 12:10:46.899|CUMULATIVE_LIMIT_USAGE 12:10:46.899|LIMIT_USAGE_FOR_NS|(default)| Number of SOQL queries: 0 out of 100 Number of query rows: 0 out of 10000 Number of SOSL queries: 0 out of 20 Number of DML statements: 0 out of 100 Number of DML rows: 0 out of 10000 Number of script statements: 10 out of 200000 Maximum heap size: 0 out of 3000000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 100 Number of record type describes: 0 out of 100 Number of child relationships describes: 0 out of 100 Number of picklist describes: 0 out of 100 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 10 Number of System.runAs() invocations: 0 out of 20 12:10:46.899|CUMULATIVE_LIMIT_USAGE_END 12:10:46.899 (69855000)|CODE_UNIT_FINISHED|VF: /apex/linkonclick 12:10:46.899 (69877000)|EXECUTION_FINISHED
But when I physically click the button it works, redirects to the correct page, and see's the users input text.
So is this a bug with salesforce?
I am not sure if this is a bug or expected behavior but you are in a bit of a pickle.
Just for grins, and I am almost positive this will not work;
change your PageReference code to this.
Again I don't think this is going to help but it's worth a shot and it's a quick fix.
Thanks, i tried that,no change with the outputlink, and when i switched it to a commandlink it still put inline=1:-(
But agian thaks for trying :-)
So I heard back from the salesforce dev team on this... and they gave me an 'answer' for one part of it... they say if you use apex:actionFunction vs using apex:actionSupport it will work.... and it does, sorta. If you use it in a stand alone VS page (not embedded inside a record view etc) it will load the pageref but if it is inside a record view like mine is, it loads the pageref but inside the iframe not the parent, like it does if you physically click the button...
So it works.... but still isn't the same behavior as a physical click.
the change looks like this: