+ Start a Discussion
Sfdc11Sfdc11 

Rerender doesn't work when given 'required=true'

When I click on command button,I want one pgblcksection to be refreshed but it's not working if the page has required="true". It should be filled only before I click save only..How to resolve???

 

<apex:page standardController="Account">
<apex:form >
<apex:pageblock >
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="2" >
<apex:inputField value="{!account.phone}" required="true"/>

</apex:pageBlockSection>

<apex:pageBlockSection >
<apex:inputField value="{!account.name}"/>
<apex:inputField value="{!account.type}"/>

</apex:pageBlockSection>

<apex:commandButton value="test" reRender="results" immediate="true"/>
<apex:outputPanel id="results">
<apex:pageBlockSection >{!(account.Name+account.type)}</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageblock>
</apex:form>
</apex:page>

PremanathPremanath

Hi if i remove required also it's not giving anything

Which pbsection you need to refresh.. The question is not cleared at ..

if you want some related code ....see my code below..

 

 

In stage field select closed Lost value..

 

<apex:page standardController="Opportunity" sidebar="false">
<apex:sectionHeader title="Edit Opportunity" subtitle="{!opportunity.name}"/>
<apex:form >
<apex:pageBlock title="Edit Opportunity" id="thePageBlock" mode="edit">
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:actionRegion >
<apex:pageBlockSection title="Basic Information" columns="1">
<apex:inputField value="{!opportunity.name}"/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Stage"/>
<apex:outputPanel >
<apex:inputField value="{!opportunity.stageName}">
<apex:actionSupport event="onchange" rerender="thePageBlock"
status="status"/>
</apex:inputField>
<apex:actionStatus startText="applying value..." id="status"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
<apex:inputField value="{!opportunity.amount}"/>
<apex:inputField value="{!opportunity.closedate}"/>
</apex:pageBlockSection>
</apex:actionRegion>
<apex:pageBlockSection title="Closed Lost Information" columns="1"
rendered="{!opportunity.stageName == 'Closed Lost'}">
<apex:inputField value="{!opportunity.Name}" required="true"/>
<apex:inputField value="{!opportunity.amount}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

prem

Rahul SharmaRahul Sharma

Hey

 

There are two options to get rid of server side validation(required field validation).

 

1. Use immediate=true for Command button:

    - This has some drawbacks(We don't get the latest values of any controller property here).

 

2. Use apex:actionRegion Tag:

    - This is very nice and works almost all the time.

    - Just enclose the buttons(for which you need to escape validation) inside the apex:actionregion.

 

Modified your code below to include apex:actionRegion tag.

<apex:page standardController="Account">
	<apex:form >
		<apex:pageblock >
			<apex:pageBlockButtons >
				<apex:commandButton action="{!save}" value="Save"/>
				<apex:commandButton action="{!cancel}" value="Cancel"/>
			</apex:pageBlockButtons>
			<apex:pageBlockSection columns="2" >
				<apex:inputField value="{!account.phone}" required="true"/>

			</apex:pageBlockSection>

			<apex:pageBlockSection >
				<apex:inputField value="{!account.name}"/>
				<apex:inputField value="{!account.type}"/>

			</apex:pageBlockSection>
			<apex:actionRegion>
				<apex:commandButton value="test" reRender="results"/>
			</apex:actionRegion>
			<apex:outputPanel id="results">
				<apex:pageBlockSection >{!(account.Name+account.type)}
</apex:pageBlockSection>
</apex:outputPanel> </apex:pageblock> </apex:form> </apex:page>

 
And one more suggestion, from the next time when you post, use the Insert Code button in the top panel for inserting code and also do follow coding intendation(It will really help you and others in reading code).

Sfdc11Sfdc11

Hi Rahul,

 

I've already tried with immdiate=true and now I've inclued Action region tag for the command button as you'd given..But It doesn't work at all ,not rerendering/no output...

NTPNTP

Hi Kavi,

 

To omit the validation issue, enclose the 'required' inputfields in actionregion tag.

<apex:actionRegion>
<apex:inputField value="{!account.phone}" required="true"/>
</apex:actionRegion>

For rerendering, just give the id of the panel you want to rerender

<apex:commandButton value="Test" reRender="op"/>
<apex:outputPanel id="op">
{!text(now())}
</apex:outputPanel>

 Hope this helps.

Thanks