1

I have created a apex:repeat section with several questions, including a apex:inputfile. Every time I add a new one, the file gets cleared but the other fields are fine.

I checked my controller to what was suggested in another post and as far as I can tell, I am already setup the correct way but no matter what, it gets cleared every time I add a new one. I cant alll the logic in the controller, but I'll post the important parts. I also cleaned some of the junk of the VP page to make it easier to read. (Left the custom date picker logic) Thanks!

One major difference with my form is I needed to use apex:actionRegion because I need to rerender a section, based on an answer and inputfile's cant be used with rerenders. Maybe that is the cause, I am not sure. Maybe I'll figure out before someone replies. Thanks for any help you can give becuase I am going insane!

Visualforce Page:

<apex:page controller="JL_Vendor_Invoice_Request_Controller" showHeader="false" action="{!SelectedVendor}">
<body style="background-color: #FFFFFF;">
<apex:form >
    <center>
        <apex:panelGrid styleClass="panelGridLarge" width="800px" border="0" cellpadding="0" columns="1">
            <apex:pageBlock id="Block">
                <div align="right">
                </div>
                <apex:panelGrid width="100%" styleClass="invoicedata" columnClasses="top1, top2" border="2" cellspacing="2" cellpadding="5" columns="2">
                    <apex:outputText styleClass="invoicefields" value="Vendor Name: "/>
                    <apex:outputText styleClass="invoicedata" value="{!Name}"/>
                    <apex:outputText styleClass="invoicefields" value="Vendor Phone: "/>
                    <apex:outputText styleClass="invoicedata" value="{!Phone}"/>
                    <apex:outputText styleClass="invoicefields" value="Vendor Email: "/>
                    <apex:outputText styleClass="invoicedata" value="{!Email}"/>
                </apex:panelGrid>
                <apex:panelGrid width="100%" border="1" styleClass="invoicedata" cellspacing="2" cellpadding="5" columns="1">
                    <apex:panelGrid border="0" styleClass="invoicedata" cellspacing="2" cellpadding="5" columns="1">
                        <apex:outputText styleClass="invoicefields" value="Vendor Address: "/>
                        <apex:outputText styleClass="invoicedata" value="{!Street}"/>
                        <apex:outputText styleClass="invoicedata" value="{!City} {!State}, {!ZipCode}"/>
                    </apex:panelGrid>
                </apex:panelGrid>
                <br/>
                <apex:variable var="count" value="{!1}"/>
                    <apex:repeat value="{!InvoiceList}" var="Invoice">
                        <apex:pageBlock title="Invoice #{!count}">
                            <apex:panelGrid border="0" width="100%" cellspacing="4" cellpadding="4" columns="1">
                                <apex:panelGrid border="0" cellspacing="4" cellpadding="4" columns="2">
                                    <span style="font-weight: bold;font-size: 14px;">Attach Invoice <span style="color:red;">*</span></span>
                                    <apex:inputFile accept="jpg, png, pdf" filename="{!Invoice.InvoiceAttFile}" contentType="{!Invoice.InvoiceAttType}" filesize="1000" size="50" value="{!Invoice.InvoiceAttBlob}"/>
                                </apex:panelGrid>
                                <apex:panelGrid border="0" cellspacing="4" cellpadding="4" columns="4">
                                    <span style="font-weight: bold;font-size: 14px;">Issue Date of Invoice <span style="color:red;">*</span></span>
                                    <apex:inputText id="IssueDate" value="{!Invoice.IssueDate}" onfocus="DatePicker.pickDate(false, this.id, false);" style="width: 70px;" />
                                    <span style="font-weight: bold;font-size: 14px;">Due Date of Invoice <span style="color:red;">*</span></span>
                                    <apex:inputText id="DueDate" value="{!Invoice.DueDate}" onfocus="DatePicker.pickDate(false, this.id, false);" style="width: 70px;" />
                                    <span style="font-weight: bold;font-size: 14px;">Invoice/Reference Number <span style="color:red;">*</span></span>
                                    <apex:inputText id="Reference" value="{!Invoice.Reference}" style="width: 100px;" />
                                    <span style="font-weight: bold;font-size: 14px;">Total Amount Due <span style="color:red;">*</span></span>
                                    <apex:inputText id="TotalDue" value="{!Invoice.TotalAmount}" maxlength="8" size="10"/>
                                </apex:panelGrid>
                                <apex:actionRegion>
                                    <apex:panelGrid border="0" cellspacing="4" cellpadding="4" columns="2">
                                        <span style="font-weight: bold;font-size: 14px;">Payment Schedule <span style="color:red;">*</span></span>
                                        <apex:selectList value="{!Invoice.PaymentSchedule}" size="1">
                                            <apex:selectOptions value="{!PaymentScheduleList}"/>
                                            <apex:actionSupport event="onchange" rerender="CustomSchedule"/>
                                        </apex:selectList>
                                    </apex:panelGrid>
                                    <apex:outputPanel id="CustomSchedule">
                                        <apex:panelGrid rendered="{!Invoice.PaymentSchedule == 'Custom'}"  width="100%" border="0" cellspacing="4" cellpadding="4" columns="2">
                                            <apex:panelGrid border="0" cellspacing="4" cellpadding="4" columns="2">
                                                <span style="font-weight: bold;font-size: 14px;">Date 01 <span style="color:red;">*</span></span>
                                                <apex:inputText value="{!Invoice.Date01}" onfocus="DatePicker.pickDate(false, this.id, false);" id="Date01" style="width: 70px;"/>
                                                <span style="font-weight: bold;font-size: 14px;">Date 02 </span>
                                                <apex:inputText value="{!Invoice.Date02}" onfocus="DatePicker.pickDate(false, this.id, false);" id="Date02" style="width: 70px;"/>
                                                <span style="font-weight: bold;font-size: 14px;">Date 03 </span>
                                                <apex:inputText value="{!Invoice.Date03}" onfocus="DatePicker.pickDate(false, this.id, false);" id="Date03" style="width: 70px;"/>
                                                <span style="font-weight: bold;font-size: 14px;">Date 04 </span>
                                                <apex:inputText value="{!Invoice.Date04}" onfocus="DatePicker.pickDate(false, this.id, false);" id="Date04" style="width: 70px;"/>
                                                <span style="font-weight: bold;font-size: 14px;">Date 05 </span>
                                                <apex:inputText value="{!Invoice.Date05}" onfocus="DatePicker.pickDate(false, this.id, false);" id="Date05" style="width: 70px;"/>
                                                <span style="font-weight: bold;font-size: 14px;">Date 06 </span>
                                                <apex:inputText value="{!Invoice.Date06}" onfocus="DatePicker.pickDate(false, this.id, false);" id="Date06" style="width: 70px;"/>
                                            </apex:panelGrid>
                                            <apex:panelGrid border="0" cellspacing="4" cellpadding="4" columns="2">
                                                <span style="font-weight: bold;font-size: 14px;">Date 07 </span>
                                                <apex:inputText value="{!Invoice.Date07}" onfocus="DatePicker.pickDate(false, this.id, false);" id="Date07" style="width: 70px;"/>
                                                <span style="font-weight: bold;font-size: 14px;">Date 08 </span>
                                                <apex:inputText value="{!Invoice.Date08}" onfocus="DatePicker.pickDate(false, this.id, false);" id="Date08" style="width: 70px;"/>
                                                <span style="font-weight: bold;font-size: 14px;">Date 09 </span>
                                                <apex:inputText value="{!Invoice.Date09}" onfocus="DatePicker.pickDate(false, this.id, false);" id="Date09" style="width: 70px;"/>
                                                <span style="font-weight: bold;font-size: 14px;">Date 10 </span>
                                                <apex:inputText value="{!Invoice.Date10}" onfocus="DatePicker.pickDate(false, this.id, false);" id="Date10" style="width: 70px;"/>
                                                <span style="font-weight: bold;font-size: 14px;">Date 11 </span>
                                                <apex:inputText value="{!Invoice.Date11}" onfocus="DatePicker.pickDate(false, this.id, false);" id="Date11" style="width: 70px;"/>
                                                <span style="font-weight: bold;font-size: 14px;">Date 12 </span>
                                                <apex:inputText value="{!Invoice.Date12}" onfocus="DatePicker.pickDate(false, this.id, false);" id="Date12" style="width: 70px;"/>
                                            </apex:panelGrid>
                                        </apex:panelGrid>
                                    </apex:outputPanel>
                                </apex:actionRegion>
                            </apex:panelGrid>
                            <apex:variable value="{!count + 1}" var="count"/>
                        </apex:pageBlock>
                    </apex:repeat>
                <apex:commandButton action="{!addInvoice}" value="Add Additional Invoice..."/>
            </apex:pageblock>
        </apex:panelGrid>
        <apex:commandButton id="Submit" value="Submit" action="{!Submit}" style="font-weight: bold;color:green;padding:4px;font-size: 16px;"/>
        <apex:actionStatus id="mystatus">
            <apex:facet name="start">
                <div style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; opacity: 0.75; z-index: 1000; background-color: black;font-family: Arial,Helvetica,sans-serif;font-size: 1.2em;">
                    &nbsp;
                </div>
            </apex:facet>
        </apex:actionStatus>
        <div class="datePicker" id="datePicker">
            <div class="dateBar">
                <img src="/s.gif" alt="Previous Month"  class="calLeft" onblur="this.className = 'calLeft';" onclick="DatePicker.datePicker.prevMonth();" onfocus="this.className = 'calLeftOn';" onmouseout="this.className = 'calLeft';" onmouseover="this.className = 'calLeftOn';" title="Previous Month"/>
                <select id="calMonthPicker" name="calMonthPicker" title="Month">
                    <option value="0">January</option>
                    <option value="1">February</option>
                    <option value="2">March</option>
                    <option value="3">April</option>
                    <option value="4">May</option>
                    <option value="5">June</option>
                    <option value="6">July</option>
                    <option value="7">August</option>
                    <option value="8">September</option>
                    <option value="9">October</option>
                    <option value="10">November</option>
                    <option value="11">December</option>
                </select>
                <img src="/s.gif" alt="Next Month"  class="calRight" onblur="this.className = 'calRight';" onclick="DatePicker.datePicker.nextMonth();" onfocus="this.className = 'calRightOn';" onmouseout="this.className = 'calRight';" onmouseover="this.className = 'calRightOn';" title="Next Month"/>
                <select id="calYearPicker" name="calYearPicker" title="Year"/>
            </div>
            <div class="calBody">
                <table class="calDays" border="0" cellpadding="0" cellspacing="0" id="datePickerCalendar">
                    <tr>
                        <TH class="dayOfWeek" scope="col">Sun</TH>
                        <TH class="dayOfWeek" scope="col">Mon</TH>
                        <TH class="dayOfWeek" scope="col">Tue</TH>
                        <TH class="dayOfWeek" scope="col">Wed</TH>
                        <TH class="dayOfWeek" scope="col">Thu</TH>
                        <TH class="dayOfWeek" scope="col">Fri</TH>
                        <TH class="dayOfWeek" scope="col">Sat</TH>
                    </tr>
                    <tr class="calRow" id="calRow1">
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                    </tr>
                    <tr class="calRow" id="calRow2">
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                    </tr>
                    <tr class="calRow" id="calRow3">
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                    </tr>
                    <tr class="calRow" id="calRow4">
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                    </tr>
                    <tr class="calRow" id="calRow5">
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                    </tr>
                    <tr class="calRow" id="calRow6">
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                        <td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td>
                    </tr>
                </table>
                <div class="buttonBar">
                    <a href="javascript:%20void%280%29%3B" class="calToday" onclick="DatePicker.datePicker.selectDate('today');return false;">Today</a>
                </div>
            </div>
        </div>
        <apex:pageMessages id="msg"/>
    </center>
</apex:form>

Controller:

public class JL_Vendor_Invoice_Request_Controller {
public List<Invoice> InvoiceList {get;set;}

public Invoice TempInvoice {get;set;}

public class Invoice {
    public blob InvoiceAttBlob {get;set;}
    public String InvoiceAttType {get; set;}
    public String InvoiceAttFile {get; set;}
    public Date IssueDate {get;set;}
    public Date DueDate {get;set;}
    public String Reference {get;set;}
    public Decimal TotalAmount {get;set;}
    public String PaymentSchedule {get;set;}
    public String Comments {get;set;}
    public Date Date01 {get;set;}
    public Date Date02 {get;set;}
    public Date Date03 {get;set;}
    public Date Date04 {get;set;}
    public Date Date05 {get;set;}
    public Date Date06 {get;set;}
    public Date Date07 {get;set;}
    public Date Date08 {get;set;}
    public Date Date09 {get;set;}
    public Date Date10 {get;set;}
    public Date Date11 {get;set;}
    public Date Date12 {get;set;}
}

public JL_Vendor_Invoice_Request_Controller() {
    SelectedVendorId = ApexPages.currentPage().getParameters().get('SelectedVendorId');
    InvoiceList = new List <Invoice>();
    InvoiceList.add(TempInvoice);
}

public void addInvoice() {
    Invoice InvoiceItem = new Invoice();
    InvoiceList.add(InvoiceItem);
}

public void SelectedVendor() {
    List<Account> SelectedAccountList = [Select Id, Name, Phone, Email__c, BillingStreet, BillingCity, BillingState, BillingPostalcode, AcctSeed__Accounting_Type__c, AcctSeed__Default_Expense_GL_Account__c, AcctSeed__Default_Expense_GL_Account__r.Name, CreatedDate from Account where Id =: SelectedVendorId];
    SelectedAccount = SelectedAccountList[0];

    Name = SelectedAccount.Name;
    Phone = SelectedAccount.Phone;
    Email = SelectedAccount.Email__c;
    Street = SelectedAccount.BillingStreet;
    City = SelectedAccount.BillingCity;
    State = SelectedAccount.BillingState;
    ZipCode = SelectedAccount.BillingPostalcode;

    addInvoice();
}

}

0

Basically, because of how input fields work in terms of browser security, and the way Visualforce renders HTML, these techniques are completely incompatible. You're not "missing" anything, it's simply not compatible. You would want to use JavaScript to render your forms and use @RemoteAction methods to interact with the server.

1
  • Thanks, I have tried to research what you mean but had no luck. I finally had to give up and just make the attachments be a separate step on the next page. I am not super experienced with Apex and just have basic knowledge and google as my tools so I am not quiet sure how to go about your suggestion. I really don't like my solution and would like them to be on the same page but I cant figure it out. – Jason Lari Apr 12 '19 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.