2

When a command link is clicked on page it is refreshing the whole page and asking to enter require fields. But I want to enter required fields only after clicking the command link.

Note:Command link is used to open a new VF page

VF Page:

                <apex:inputField value="{!Account.Name}" required = true>

                   </apex:inputField>

              <apex:outputPanel >
              <apex:outputField  value="{!Account.Input__c}" />
             <apex:commandLink  action="{!redirectToVFPage}" target="_blank">
</apex:commandLink>
             </apex:outputPanel>
4
  • 4
    Just add a rerender="none" attribute.
    – Adrian Larson
    Commented Jul 20, 2017 at 18:56
  • @AdrianLarson I already tried rerender="none". But when I click command link it is not working (Not able to open VF page)
    – Learner
    Commented Jul 20, 2017 at 20:07
  • I think you meant to use <apex:outputLink> instead, perhaps...
    – Adrian Larson
    Commented Jul 20, 2017 at 20:16
  • use immediate="true" during submission. rerender="none" will not work. check my answer Commented Jul 20, 2017 at 20:35

4 Answers 4

2

You have two things going on here:

  1. Refresh - Without rerender the entire page is reloaded
  2. Required fields - If the field is required it must be populated when there is no rerender

Here is the most basic example to help you out, put it in your org and play with it a bit to see the effect of different options.

Class

public class myExample{

    public Account acc {get; set;}

    public myExample(){
        acc = New Account();
    }
    public void updateCurrentRecord(){
        //Do some stuff        
    }

}

VF Page

<apex:page id="myExamplePage" controller="myExample">
    <apex:pageMessages id="msgs"/>
    <apex:form >
        <apex:commandLink action="{!updateCurrentRecord}" reRender="thePanel, msgs" value="Click me"/>
            <apex:inputField value="{!acc.Name}" required="true"/>

        <apex:outputpanel layout="block" id="thePanel">

            {!acc.Name}

        </apex:outputpanel>


    </apex:form>


</apex:page>

Note you need to add the Page Messages component to see the required validation error when using rerender. Also, displaying the error at the field level requires you to NOT use the rerender attribute.

Its all a bit confusing.....

This will not refresh the page but will refresh the output panel to show the update. You could leave the rerender=none and debug the values in the controller and see that it works.

If you remove the rerender from the command link, you will see your issue return.

Using Immediate=true will not send the value to the controller and the thePanel panel will be blank on rerender.

  • If used without rerender - Page will refresh and your values will not save
  • If used with the rerender - Page will not refresh and values will not be saved

Another item to review would be action regions, but may not be applicable in your use case. If you need to submit part of the form and not the others (having required fields) look into that.

Only use immediate=true when you want to cancel any inputs and do the action immediately - think a cancel redirect. If you want to open your new page without accepting any inputs the user entered then do use immediate=true

1

You need to use immediate="true" so that page will ignore validations during submission.

immediate = A Boolean value that specifies whether the action associated with this component should happen immediately, without processing any validation rules associated with the fields on the page. If set to true, the action happens immediately and validation rules are skipped. If not specified, this value defaults to false.

<apex:inputField value="{!Account.Name}" required = true>

</apex:inputField>

<apex:outputPanel >
<apex:outputField  value="{!Account.Input__c}" />
<apex:commandLink  action="{!redirectToVFPage}" target="_blank" immediate="true">
</apex:commandLink>
</apex:outputPanel>
1
  • 2
    "ignore validations during submission" is not the reason for the refresh but is the reason for the required fields. Additionally adding immediate=true may cause unexpected side effects as any data entered into the inputs will not be passed to the server. Since we do not have the full picture you should probably expand on that a bit as well.
    – Eric
    Commented Jul 20, 2017 at 20:37
0
<apex:commandLink action="{!redirectToVFPage}" target="_blank" rerender="none" > 

In the commandLink section add and attribute: rerender="none"

2
  • I already tried rerender="none". But when I click command link it is not working (Not able to open VF page)
    – Learner
    Commented Jul 20, 2017 at 19:29
  • @Learner The reason why you are not being redirect is because the field is required. See my answer
    – Eric
    Commented Jul 20, 2017 at 21:14
0

If don't want render the page just keep the rerender value to Empty, its will avoid from re-rendering page.

<apex:commandLink action="{!redirectToVFPage}" target="_blank" rerender="" >

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .