3
votes

I have a repeat control on my XPage:

    <xp:repeat id="DriverRepeat" var="rowData" indexVar="rowIndex" value="#{javascript:requestBean.getDrivers();}">
        <xp:label value="#{javascript:rowData.driverInfo}" />
        <xp:inputText value="#{requestBean.driverChanges}" />
    </xp:repeat>

I have a managed bean (requestBean) bound to my XPage. I'm able to read/save other non-repeat control values using value="#{requestBean.driverChanges}" and in my Java bean:

private String driverChanges;

getter/setters:

public void setDriverChanges(String driverChanges) {
    this.driverChanges = driverChanges;
}

public String getDriverChanges() {
    return driverChanges;
}

load value:

setDriverChanges(doc.getItemValueString("DriverChanges"));

save value:

doc.replaceItemValue("DriverChanges", driverChanges);

But this doesn't work with repeat control fields because they are multi-valued. I tried making driverChanges a Vector but I wasn't sure how to structure the inputText field value with the managed bean. Thanks in advance for any ideas.

1
What does driverChanges contain? Is it a multi-value field for one driver each or one field for all drivers together?Knut Herrmann
@KnutHerrmann - I need a text field for each driver to indicate what is changing on that specific driver. So that field is repeated for each driver. This is where I'm unsure how to bind it to my managed bean.Ryan Buening

1 Answers

4
votes

According to your question and your comments you have a requestBean which represents a Request document. This document has two multi value fields

  • DriverInfo
  • DriverChanges

Each element of multi value list represents a driver. First driver's info is in first element of DriverInfo and first driver's changes are in first element of DriverChanges and so on.

DriverInfo    DriverChanges
driver1       changes1
driver2       changes2
driver3       changes3

You'd like to create a repeat control which shows data for each driver in a separate line like this

enter image description here

Change your requestBean to

public class RequestBean implements Serializable {
    ...

    private Vector<String> driverInfo;
    private Vector<String> driverChanges;

    public Vector<String> getDrivers() throws Exception {
        ...
        setDriverInfo(doc.getItemValue("DriverInfo"));
        setDriverChanges(doc.getItemValue("DriverChanges"));
        return driverInfo;
    }

    public void setDriverInfo(Vector<String> driverInfo) {
        this.driverInfo = driverInfo;
    }

    public Vector<String> getDriverInfo() {
        return driverInfo;
    }

    public void setDriverChanges(Vector<String> driverChanges) {
        this.driverChanges = driverChanges;
    }

    public Vector<String> getDriverChanges() {
        return driverChanges;
    }

    public void save() throws Exception {
        ...
        doc.replaceItemValue("driverInfo", getDriverInfo());
        doc.replaceItemValue("driverChanges", getDriverChanges());
        doc.save();
    }
}

and change your repeat control to

<xp:repeat
    id="DriverRepeat"
    var="rowData"
    indexVar="rowIndex"
    value="#{javascript:requestBean.getDrivers()}">
    <xp:label value="#{rowData}" />
    <xp:inputText value="#{requestBean.driverChanges[rowIndex]}" />
    <br />
</xp:repeat>

requestBean.getDrivers() returns a Vector of driverInfos. rawData holds the driverInfo for current driver inside repeat.
requestBean.driverChanges[rowIndex] calls requestBean's method getDriverChanges(), returns a Vector of driverChanges and selects only the value for current driver with rowIndex.