function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
doudou 

save method

Hi,
I'm trying to built a saving method into my apex controller.
I have a few fiels in my visualforce page, like this :
<apex:form >
			<div id="colonne1">
				<p id="oeuvreEtOpportunite">
					<span>Oeuvre</span>
					<apex:inputText value="{!droit.Oeuvre__r.Name}"></apex:inputText>&nbsp;
					<span>Opportunité</span>
					<apex:inputText value="{!droit.Opportunite__r.Name}"></apex:inputText>
				</p>
				<p id="dateDebutDetention">
					<span>Date de début de détention</span>
					<apex:inputText id="datepicker" value="{!choixDate}"></apex:inputText>
				</p>
				<p id="dureeDetention">
					<span>Durée de détention</span>
					<apex:inputText value="{!droit.Duree_de_detention__c}"></apex:inputText>
				</p>
			</div>
			<div id="colonne2">
				<p>
					<apex:inputCheckbox value="{!droit.Accord_producteur__c}" id="accordProd"></apex:inputCheckbox>
					<span>Accord producteur</span>
				</p>
				<p>
					<apex:inputCheckbox value="{!droit.Exclusivite__c}" id="exclusivite"></apex:inputCheckbox>
					<span>Exclusivité</span>
				</p>
				<p>
					<apex:inputCheckbox value="{!droit.Option__c}" id="option"></apex:inputCheckbox>
					<span>Option</span>
				</p>
			</div>
		</apex:form>

And I want to save the value the user enter in this fields, with a button like this :
<apex:form id="dummy">
		
		<apex:commandButton value="Enregistrer" action="{!enregistrer}" />
		<apex:commandButton value="Annuler" onclick="window.close();"/>

</apex:form>

So, in my apex controller I have to add the "enregistrer" method for saving the values :
public Droit__c droit {get; set;}
    public String choixDate {get; set;}

public String droitId {get; set;}

public GestionDroitsController() {
        droitId = ApexPages.currentPage().getParameters().get('droitId');

        droit = [SELECT Id, Oeuvre__r.Name, Opportunite__r.Name, Duree_de_detention__c, Accord_producteur__c, Exclusivite__c, Option__c, Date_de_debut_de_detention__c
                FROM Droit__c WHERE Id = :droitId LIMIT 1];
    }
public void enregistrer(){

		if(droitId != null){
			//Droit__c droit;
			droit.Date_de_debut_de_detention__c = getDateFromString(choixDate);
			update droit;
}
}
But I don't know how to make the method working, so if you know how to make that, thank you for your answers ! :)
 
Best Answer chosen by dou
pconpcon
This should work.  The only thing that may be the cause of your issue is that you have to apex:form tags  I think you'll want to include you apex:commandButton as part of the form with all of your other apex:input options.  If you try this and find that it still doesn't work, please include the entire Visualforce page in a single code sample.

All Answers

pconpcon
This should work.  The only thing that may be the cause of your issue is that you have to apex:form tags  I think you'll want to include you apex:commandButton as part of the form with all of your other apex:input options.  If you try this and find that it still doesn't work, please include the entire Visualforce page in a single code sample.
This was selected as the best answer
doudou
Yes you're right I put the apex:commandButton into the same apex:form than the apex:inputText and checkboxes and it's working ! Thank you !