I want to insert a command button called Edit in my view page. All fields are in output mode, and when I click on the Edit button I want to type on them or make changes. (In my Scenario inlineEdit does not work). Can anybody please help me. Thanks
-
I add a edit button it does not work the way i want. I want to edit all my output field when i click the edit. It should in the same page and should activate the output fields into input field. So i can type <apex:commandButton value="Edit2" action="{!URLFOR($Action.Product_Brief__c.Edit,Product_Brief__c.Id)}"/> This is not the way i want.– Dananjaya PathiranaCommented Jun 22, 2015 at 14:40
Add a comment
|
1 Answer
I think you would have to use a boolean in your controller which controls if the fields can be edited or not :
In your controller :
public Boolean bEditMode {
get {
if(bEditMode == null) {
bEditmode = false;
}
return bEditMode;
}
set;
}
public PageReference doToggleEditMode() {
bEditMode = !bEditMode;
return null;
}
public PageReference doSave() {
try {
// Do your stuff to save your record
doToggleEditMode();
}
catch(Exception ex) {
// Handle error
}
return null;
}
In your VFPage :
<apex:outputPanel id="myPanel">
<apex:commandButton action="{!doToggleEditMode}" value="Edit" reRender="myPanel" rendered="{!NOT(bEditMode)}" />
<apex:commandButton action="{!doSave}" value="Save" reRender="myPanel" rendered="{!bEditMode}" />
<apex:outputText value="{!someVar}" rendered="{!NOT(bEditMode)}" />
<apex:inputText value="{!someVar}" rendered="{!bEditMode}" />
</apex:outputPanel>
I think that would do the job. Let me know if it doesn't.
-
Thank you very much. I have done so many thing but does not work the way i want. I will try this one and let you know. Once again thanks. Commented Jun 22, 2015 at 14:58
-
Hey Julien Gaïotto, It gives me a error "Error: justing Compile Error: Non-void method might not return a value or might have statement after a return statement." Commented Jun 22, 2015 at 15:14
-
public class justing { public Boolean bEditMode { get { if(bEditMode == null) { bEditmode = false; } return bEditMode; } set; } public PageReference doToggleEditMode() { bEditMode = !bEditMode; } public PageReference doSave() { try { // Do your stuff to save your record doToggleEditMode(); } catch(Exception ex) { // Handle error } } public justing(ApexPages.StandardController controller) { } } Commented Jun 22, 2015 at 15:16
-
Ooops completely forgot to return null in the doToggleEditMode and doSave methods :/ I edited my post so that it is correct know Commented Jun 22, 2015 at 15:17
-
1Hey Thank you very much. I think this the way i want it. Your the best. Once again thank you very much. Commented Jun 22, 2015 at 15:22