Setting / getting values ​​in replay control with Managed Java Bean

I have a re-control in 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 can read / store other control values ​​without repeating 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"));

      

store value:

doc.replaceItemValue("DriverChanges", driverChanges);

      

But this doesn't work with redo fields because they are multi-valued. I tried to make a driverChanges

vector, but wasn't sure how to structure the value of the inputText using a managed bean. Thanks in advance for any ideas.

+3


source to share


1 answer


As per your question and your comments, you have requestBean, which is a Request document. This document has two fields with multiple values

  • DriverInfo
  • DriverChanges

Each item in the multi-valued list represents a driver. The first driver information is in the first DriverInfo element, and the first driver changes are in the first DriverChanges element, and so on.

DriverInfo    DriverChanges
driver1       changes1
driver2       changes2
driver3       changes3

      

You want to create a redo control that shows the data for each driver on a separate line like this

enter image description here



Change 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 the 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 the vector driverInfos. rawData

contains the driverInfo for the current driver inside the replay.
requestBean.driverChanges[rowIndex]

calls the requestBean method getDriverChanges()

, returns the vector driverChanges, and fetches only the value for the current driver with rowIndex.

+4


source







All Articles