Search code examples
javajsfservletsicefacesjsf-1.2

Icefaces 1.8 SelectInputText String value auto-complete


Seems to be some silly mistake in my code but not able to figure it out :(

I have a SelectInputText component in a screen. On selecting a String value from the auto-complete functionality, I need to display the details in a PanelGrid. The SelectInputText functionality is working fine i.e. the auto-complete is displaying correct values. When I select a value from the auto-complete list, I am not able to display the values in the PanelGrid.

Below is the jspx:

<ice:form>
             <ice:panelGroup>
                <ice:outputText value="Name: "/>        
                <ice:selectInputText id="AutoCmpTxt"
                                     rows="#{nameBean.nameListLength}"
                                     width="300"
                                     value="#{nameBean.name}"
                                     valueChangeListener="#{nameBean.selectInputValueChanged}">
                    <f:selectItems id="AutoCmpTxtItms"
                                   value="#{nameBean.availableNames}"/>
                </ice:selectInputText>
            </ice:panelGroup>           
            <ice:panelGrid columns="2" rendered="#{studentDetail.visible }">
                <ice:outputLabel value="Name"></ice:outputLabel>
                <ice:outputText value="#{studentDetail.name }"></ice:outputText>
                <ice:outputLabel value="Age"></ice:outputLabel>
                <ice:outputText value="#{studentDetail.age }"></ice:outputText>
                <ice:outputLabel value="Gender"></ice:outputLabel>
                <ice:outputText value="#{studentDetail.gender }"></ice:outputText>
                <ice:outputLabel value="Location"></ice:outputLabel>
                <ice:outputText value="#{studentDetail.location }"></ice:outputText>
            </ice:panelGrid>
        </ice:form>

Below is the NameBean.java

public class NameBean {

private List<SelectItem> availableNames;
private String name;
private int nameListLength = 3;
private StudentDetails studentDetails;

public int getNameListLength() {
    return nameListLength;
}

public NameBean() {
    availableNames = new ArrayList<SelectItem>();
    studentDetails = new StudentDetails();
}

public List<SelectItem> getAvailableNames() {
    return availableNames;
}

public void setAvailableNames(List<SelectItem> availableNames) {
    this.availableNames = availableNames;
}

public void selectInputValueChanged(ValueChangeEvent event){

    if(event.getComponent() instanceof SelectInputText){            
        SelectInputText autoComplete = (SelectInputText) event.getComponent();
        String value = (String)event.getNewValue();
        DataService service = new DataService();
        this.availableNames = service.getAvaliableNames(value);

        if (autoComplete.getSelectedItem() != null) {
            System.out.println("Selected");
            String name = (String) autoComplete.getSelectedItem().getValue();
            System.out.println("Name Selected: " + name);
            StudentDetails details = getAvaliableNames(name);
            if (details != null){
                this.studentDetails = details;
            }                
        }
        else{
            System.out.println("Still Not Selected!!!");
            StudentDetails details = getAvaliableNames(value);
            if (details != null){
                this.studentDetails = details;
            }
        }
}
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

private StudentDetails getAvaliableNames(String name){
           //This will return a StudentDetails Model with some data
}

}

The StudentDetails bean is a class with soem getters and setters only.

Below is the managed bean entry:

<managed-bean>     
    <managed-bean-name>nameBean</managed-bean-name>
    <managed-bean-class>com.infy.bean.NameBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>        
</managed-bean>
<managed-bean>
    <managed-bean-name>studentDetail</managed-bean-name>
    <managed-bean-class>com.infy.bean.StudentDetails</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>        
</managed-bean> 

Please let me know what am I missing (has to be something very silly :( )


Solution

  • Ok I changed the PanelGrid to this and it worked for me:

    <ice:panelGrid columns="2" rendered="#{nameBean.studentDetails.visible }">
                    <ice:outputLabel value="Name"></ice:outputLabel>
                    <ice:outputText value="#{nameBean.studentDetails.name }"></ice:outputText>
                    <ice:outputLabel value="Age"></ice:outputLabel>
                    <ice:outputText value="#{nameBean.studentDetails.age }"></ice:outputText>
                    <ice:outputLabel value="Gender"></ice:outputLabel>
                    <ice:outputText value="#{nameBean.studentDetails.gender }"></ice:outputText>
                    <ice:outputLabel value="Location"></ice:outputLabel>
                    <ice:outputText value="#{nameBean.studentDetails.location }"></ice:outputText>
                </ice:panelGrid>