You need to sign in to do that
Don't have an account?
***Urgent Help*** adding Command link to rerender few dynamic fields on VF
Hi All,
I have a requirment in the VF page as :
required+Optional is a link and on clicking on which the 5 fields mentioned below need to be re rendered.
by default office name , Address 1 , city and state would be seen. After clicking on Required+optional link, the page should show Address2 and the link name should get changed to "Required Only". And another click on the "Require Only" link should changed back to "Required+Optional" Can someone please help me with the code. All the fields are created in a object called Office Location.
Required+optional
Office name
Address 1 -- This field will have to be shown only when link is clicked
Address 2
City
State
Thanks
Manju
it worked., added immediate="true in the commandclick.
Thanks Ashish for your help.
All Answers
Hi
Try this...
This is my page
<apex:page controller="ForumsolveController">
<apex:form>
<apex:pageBlock title="Commandlink & Rendred Problem">
<apex:pageBlockSection title="OfficeLocation Field" columns="2" id="section">
<apex:inputField value="{!officeloc.Name}"/>
<apex:inputField value="{!officeloc.State__c}"/>
<apex:inputField value="{!officeloc.City__c}"/>
<apex:inputField value="{!officeloc.Address1__c}"/>
<apex:inputField value="{!officeloc.Address2__c}" rendered="{!visible=='hi'}"/><br/>
<apex:commandLink value="Required + Optional" action="{!test}" reRender="section" rendered="{!visible!='hi'}"/>
<apex:commandLink value="Required Only" action="{!test}" rendered="{!visible=='hi'}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
My controller is......
public class ForumsolveController {
public OfficeLocation__c officeloc{get;set;}
public String visible{get;set;}
public ForumsolveController(){
}
public PageReference Test(){
visible = 'hi';
return null;
}
}
Did this post answers your problem..If so please mark it solved so that others get benifited...
thanks
asish
Hi Ashish,
Thanks for your reply.
I tried the code u had given , what it does is when the page is loaded, the Address 2 field is hidden coz of the rendered functionality, but the link Required+only stay as it is.
At first I will display Required+only Link. with the address2 field hidden.
When i click on Required+Only The field Address2 should be visible and the link name should change to Required
similarly when the Required is visible and clicked on it, it should hide the address2 field and change the link name to Required+Optional
Please help me with your expertise.
Thanks
Manju
Hi
Try this...
<apex:commandLink value="Required Only" action="{!test1}" rendered="{!visible=='hi'}"/>
In controller add one method test1...
here is....
public PageReference Test1(){
visible = 'heloo';
return null;
}
Did this post answers your questions..If so please mark it solved by clicking Accept as solutions buttom..
Thanks
asish
Ashish,
Please take a look at my code :
VF page :
<apex:pageBlocksection id="section" columns="2" title="Personal Information" collapsible="false">
<apex:panelGrid width="700" columns="3">
<apex:outputlabel ></apex:outputlabel>
<apex:outputlabel ></apex:outputlabel>
<apex:commandLink value="(Required + Optional)" action="{!Test}" reRender="section" rendered="{!visible!='hi'}"/>
<apex:commandLink value="(Required Only)" action="{!Test1}" reRender="section" rendered="{!visible=='heloo'}"/>
<apex:outputLabel value="Prefix" for="prefix" rendered="{!visible=='hi'}"/>
<apex:inputText required="false" id="prefix" value="{!prefix}" rendered="{!visible=='hi'}"/>
<apex:outputlabel ></apex:outputlabel>
<apex:outputLabel value="First Name" for="fname"/>
<apex:inputText required="false" id="fname" value="{!fname}"/>
<apex:outputlabel ></apex:outputlabel>
<apex:outputLabel value="Last Name" for="lname"/>
<apex:inputText required="false" id="lname" value="{!lname}"/>
<apex:outputlabel ></apex:outputlabel>
<apex:outputLabel value="Middle Initial" for="mini"/>
<apex:inputText required="false" id="mini" value="{!mini}"/>
</apex:panelgrid>
</apex:pageblockSection>
and have added the two methods as suggested in My controller :
public PageReference Test(){
visible = 'hi';
return null;
}
public PageReference Test1(){
visible = 'heloo';
return null;
}
.
What is happening is,
it is showing the Required+Optional link with the prefix field hidden.
I want the prefix field hidden with Required+Optional and on click of it, the link name should change to Required Only and prefix field to be visible.
Please correct me.
Thanks
Manju
Hi
You need to change this line
<apex:commandLink value="(Required Only)" action="{!Test1}" reRender="section" rendered="{!visible=='heloo'}"/>
please write
<apex:commandLink value="(Required Only)" action="{!Test1}" reRender="section" rendered="{!visible=='hi'}"/>.
when you run the page Prefix field will be hidden ..when you click on Required+optional then Prefix is visible and link is changed ti Required only .
After that when you click on Required only link then again Prefix field will be hidden and link is changed to Required+optional
Did this answers your problem ...please mark it solved
thanks
asish
Hi Ashish
I made the changes, but it is not rendering .. the link stays the same and the field never becomes visible on click of the link. I cannot find anything in the debug logs. it is not even getting created under monitoring . Please help.
<apex:pageBlockSection columns="2" id="section" title="Personal Information" collapsible="false">
<apex:panelGrid width="700" columns="3" >
<apex:outputlabel ></apex:outputlabel>
<apex:outputlabel ></apex:outputlabel>
<!--apex:commandLink value="(Required + Optional)"/-->
<apex:commandLink value="(Required + Optional)" action="{!Test}" reRender="section" rendered="{!visible!='hi'}"/>
<apex:commandLink value="(Required Only)" action="{!Test1}" reRender="section" rendered="{!visible=='hi'}"/>
<apex:outputLabel value="Prefix" for="prefix" rendered="{!visible=='hi'}"/>
<apex:inputText required="false" id="prefix" value="{!prefix}" rendered="{!visible=='hi'}"/>
<apex:outputlabel ></apex:outputlabel>
<apex:outputLabel value="First Name" for="fname"/>
<apex:inputText required="false" id="fname" value="{!fname}"/>
<apex:outputlabel ></apex:outputlabel>
<apex:outputLabel value="Last Name" for="lname"/>
<apex:inputText required="false" id="lname" value="{!lname}"/>
<apex:outputlabel ></apex:outputlabel>
<apex:outputLabel value="Middle Initial" for="mini"/>
<apex:inputText required="false" id="mini" value="{!mini}"/>
</apex:panelgrid>
</apex:pageblockSection>
Controller
public regExtn(ApexPages.StandardController controller) {
lstInner = new List<innerClass>();
addMore();
selectedRowIndex = '0';
//---------------------------------
offloc= new List<Office_Location__c>();
offloc.add(new Office_Location__c());
}
public PageReference Test(){
visible = 'hi';
return null;
}
public PageReference Test1(){
visible = 'hello';
return null;
}
Hi
please try this
<apex:pageBlockSection columns="2" id="section" title="Personal Information" collapsible="false"> <apex:panelGrid width="700" columns="3" >
<apex:commandLink value="(Required + Optional)" action="{!Test}" reRender="section" rendered="{!visible!='hi'}"/> <apex:commandLink value="(Required Only)" action="{!Test1}" rendered="{!visible=='hi'}"/>
<apex:outputLabel value="Prefix" for="prefix" rendered="{!visible=='hi'}">
<apex:inputText required="false" id="prefix" value="{!prefix}"/>
</apex:outputLabel>
<apex:outputLabel value="First Name" for="fname">
<apex:inputText required="false" id="fname" value="{!fname}"/>
</apex:outputlabel>
<apex:outputLabel value="Last Name" for="lname">
<apex:inputText required="false" id="lname" value="{!lname}"/>
</apex:outputlabel>
<apex:outputLabel value="Middle Initial" for="mini">
<apex:inputText required="false" id="mini" value="{!mini}"/>
</apex:outputlabel>
</apex:panelgrid>
</apex:pageblockSection>
Thanks
asish
Hi,
No luck ashish..
I dont know what is causing this issue. The prefix field is hidden when the page is first loaded, but is not visible on click.
Any other thing we can do ? Please help.
Also just wanted to know, in the test method,
we set the visible = 'hi' and return null. should we make any changes here ?
Thanks
Manju
it worked., added immediate="true in the commandclick.
Thanks Ashish for your help.
Hi Ashish,
Is there anyway we can fix the alignment of the required+optional link and required only link?
I mean, required only should be replaced in the same place where required+optional will be present at first instance..
Thanks
Manju
Hi
Try this....
<apex:page controller="ForumsolveController">
<apex:form>
<apex:pageBlock title="Commandlink & Rendred Problem">
<apex:pageBlockSection title="OfficeLocation Field" columns="2" id="section">
<apex:inputField value="{!officeloc.Name}"/>
<apex:inputField value="{!officeloc.State__c}"/>
<apex:inputField value="{!officeloc.City__c}"/>
<apex:inputField value="{!officeloc.Address1__c}"/>
<apex:outputLabel value="" rendered="{!visible!='hi'}"></apex:outputLabel>
<apex:inputField value="{!officeloc.Address2__c}" rendered="{!visible=='hi'}"/><br/>
<apex:commandLink value="Required + Optional" action="{!test}" reRender="section" rendered="{!visible!='hi'}"/>
<apex:commandLink value="Required" action="{!test1}" rendered="{!visible=='hi'}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Address2__c field willbe visible after clicking link and in same place Required Only link will be avilable...
Did this post solve your problem..If so please mark it solved
Thanks
asish