1

我的代码中似乎有一些愚蠢的错误,但无法弄清楚:(

SelectInputText在屏幕上有一个组件。从自动完成功能中选择字符串值时,我需要在PanelGrid. 该SelectInputText功能工作正常,即自动完成显示正确的值。当我从自动完成列表中选择一个值时,我无法在PanelGrid.

下面是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>

下面是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
}

}

StudentDetailsbean 是一个只有 soem getter 和 setter 的类。

以下是托管 bean 条目:

<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> 

请让我知道我错过了什么(必须是非常愚蠢的东西:()

4

1 回答 1

1

好的,我将其更改PanelGrid为这个,它对我有用:

<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>
于 2013-04-13T13:39:01.320 回答