I have two required fields inside a Visualforce Page
: prodottoservizio
, quant
. Inside the page I can build a list of objects shown inside a table. Now I want to insert a Delete Button that deletes all the object records created inside the controller extension and return to the previous URL.
Here my VF code:
<apex:PageBlock id="contratto">
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!createContr}" value="Scegli i Prodotti" reRender="panprodotti" />
<apex:commandButton action="{!deleteContract}" value="Elimina Contratto e prodotti selezionati" onclick="window.history.back()" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="Specifiche Contratto">
<apex:input required="true" label="Data inizio contratto" value="{!cData}" type="date" id="datainiziocontr" />
<apex:input required="true" label="Durata contratto(mesi)" value="{!cDurata}" type="number" id="durcontr" />
<apex:input label="Condizioni speciali" value="{!cCondizioni}" type="text" id="condizioni" />
</apex:pageBlockSection>
</apex:PageBlock>
apex:outputPanel id="panprodotti">
<apex:pageBlock rendered="{!cData<>null}">
<apex:pageBlock id="pselected">
<apex:pageBlockSection title="Inserisci i Prodotti" collapsible="false" >
<apex:inputField required="true" id="prodottoservizio" value="{!prodotto.Scelta__c}"/>
<apex:inputField id="gionol" value="{!prodotto.Giorni_durata_noleggio__c}"/>
<apex:inputField required="true" id="quant" value="{!prodotto.Quantit_prodotto__c}"/>
<apex:inputField id="sconto" value="{!prodotto.Sconto__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!addFromShoppingCart}" value="Aggiungi al Contratto" reRender="pinserted,panprodotti" />
</apex:pageBlockButtons>
</apex:pageBlock>
and this is my function:
public void deleteContract(){
delete shoppingCart;
delete nuovocontratto;
}
When I click the button I have an error because that two fields are required. How How can I solve this Problem?
P.S. I posted a code's portion because the controller is huge.
commandButton
in your posted markup? It callsaddFromShoppingCart
, notdeleteContract
.false
is the default value for theimmediate
property...