1

I have primefaces datatable which has 4 to 5 input components. One of the input is p:autocomplete. There is a option to add new row through UI, i have added first row later i am trying to add 2nd row whatever value selected in the first row it remains same in the 2nd row. Along with that if i choose different value in the 2nd through autocomplete that value is reflecting for both the rows.

But i would like to retain the value which is selected for first row then i need to retain the 2nd row value differently.

Note: I have used p:selectonemenu inorder to show the values from DB, it has 10000+ records it is taking more time. Due to performance issue i had gone for p:autocomplete

Please see the code XHTML code- LocationDetails.xhtml

 <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">

 <h:form id="atcs">
<p:dataTable var="atcscirreq" id="atcscirreqtbl"
    value="#{atcsCircuitIdAddressRequestBean.atcsAddressCircuitRequestList}"
    binding="#{atcsCircuitIdAddressRequestBean.dataTable}" lazy="true"     resizableColumns="true">
<p:column id="locn">
<p:autoComplete id="lcnLst" required="true"
    requiredMessage="LocationName is required field"
    converter="locationNameAutoCompleteConverter"
    completeMethod="#{atcsCircuitIdAddressRequestBean.locationNames}"
    var="locn" itemLabel="#{locn.locName}" itemValue="#{locn}"
    value="#{atcsCircuitIdAddressRequestBean.locnInfo}"
    emptyMessage="No Records Found" maxResults="10"
    forceSelection="true">
</p:autoComplete>
</p:column>
</p:dataTable>

<p:commandButton value="Add Another Request" action="#   {atcsCircuitIdAddressRequestBean.addNewRequestData}" update="atcscirreqtbl">

</h:form>

ATCSCircuitIdAddressRequestBean.java

package com.bean.request;

public class ATCSCircuitIdAddressRequestBean {

TblTrackLocationinformation locnInfo = new TblTrackLocationinformation();
List<TblTrackLocationinformation> filteredLocations = new ArrayList<TblTrackLocationinformation>();
private List<TblTrackLocationinformation> atcsAddressCircuitRequestList = new ArrayList<TblTrackLocationinformation>();

public List<TblTrackLocationinformation> locationNames(String name) {
    List<TblTrackLocationinformation> allLocations = service.getAllLocations;
    if (name.trim().equals(""))
        return allLocations;
    for (int i = 0; i < allLocations.size(); i++) {
        TblTrackLocationinformation data = allLocations.get(i);
        if (data.getLocName().toString()
                .contains(name)
                || data.getLocName().toLowerCase()
                        .contains(name.toLowerCase())) {
            filteredLocations.add(data);
        }
    }

    return filteredLocations;
}

public TblTrackLocationinformation getLocnInfo() {
    return locnInfo;
}

public void setLocnInfo(TblTrackLocationinformation locnInfo) {
    this.locnInfo = locnInfo;
}
public void addNewRequestData() {
    TblTrackLocationInformationdata = new TblTrackLocationInformation();
    filteredLocations=new ArrayList<TblTrackLocationinformation>();
    atcsAddressCircuitRequestList.add(data);
}
}

TblTrackLocationInformation.java

package com.bean.request;

public class TblTrackLocationInformation{

private String locName;
private Integer locationId;

public String getLocName() {
    return locName;
}

public void setLocName(String locName) {
    this.locName = locName;
}

public Integer getLocationId() {
    return locationId;
}

public void setLocationId(Integer locationId) {
    this.locationId = locationId;
}

}

LocationNameAutoCompleteConverter.java

package com.bean.request;
@FacesConverter("locationNameAutoCompleteConverter")
public class LocationNameAutoCompleteConverter implements Converter{

LocationInfoDAO locnDao = new LocationInfoDAOImpl();


@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
    return locnDao.getLocationInfoById(Integer.valueOf(value));
}

@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
    return String.valueOf(((TblTrackLocationinformation) value)
            .getLocationId());
}

}

Specifications of the projects are JSF 2.1, Primefaces 5.0,Servlet 2.5

I have searched many links but i did not get answer. I am checking this for past 2 days. Please help me out !

8

1 Answer 1

0

After long time, i came to know the solution. We need to know when and how to use List with object and List with String. Have to use

public List<String> locationNames(String name)

instead of

public List<TblTrackLocationinformation> locationNames(String name)

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.