0

AJAX呼び出し後にバックエンドからオプションを特定の値に設定しようとしていますが、他のすべてのフィールドタイプは正常に設定されていますが、selectOneMenuはそうではありません。Primefaces/JSFを使用しています。

xhtml:

<p:inputText id="cpr" value="#{customerbean.customer.cpr}">
                <p:ajax event="change" listener="#{customerbean.fetchCustomerDatafromCBS}" update="@form" immediate="true" >
                    <f:param name="cprNumber" value="#{customerbean.customer.cpr}"/>
                </p:ajax>                 
                <f:validator validatorId="cprValidator" />                    
            </p:inputText>   


                <p:selectOneMenu id="gender" value="#{customerbean.customer.gender}" required="#{!customerbean.disabled}" requiredMessage="#{text['validation.error.required.gender']}" disabled="#{customerbean.disabled}">                      
                <f:selectItem itemLabel="Select One" itemValue="" noSelectionOption="true" />  
                <f:selectItem itemLabel="Male" itemValue="Male" />  
                <f:selectItem itemLabel="Female" itemValue="Female"  />  
                </p:selectOneMenu>

豆:

        getCustomer().setGender(fetchedCustomer.getGender().trim());

: 値が設定されていることを発見しました (データベース行が正しい値で挿入されるため) - しかし、ブラウザーの selectOneMenu UI オブジェクトはそれを反映していません。

全体図:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

    <ui:composition template="commonLayout.xhtml">

        <ui:define name="content">

            <p:panelGrid columns="2" styleClass="companyHeaderGrid" >  
                <f:facet name="header">  
                    Create customer
                </f:facet>  

                <h:outputLabel for="cpr" value="CPR" />
                <h:outputLabel for="passportno" value="Passport No." />

                <p:inputText id="cpr" value="#{customerbean.customer.cpr}">
                    <p:ajax event="change" listener="#{customerbean.fetchCustomerDatafromCBS}" update="@form" immediate="true" >
                        <f:param name="cprNumber" value="#{customerbean.customer.cpr}"/>
                    </p:ajax>                 
                    <f:validator validatorId="cprValidator" />                    
                </p:inputText>   

                <p:inputText id="passportno" value="#{customerbean.customer.passportno}" readonly="#{customerbean.disabled}">                
                    <f:validator validatorId="passportnoValidator" />
                </p:inputText>                          

                <h:outputLabel for="name" value="Name"/>                
                <h:outputLabel for="nationality" value="Nationality" />

                <p:inputText id="name" value="#{customerbean.customer.name}" required="true" requiredMessage="#{text['validation.error.required.name']}" readonly="#{customerbean.disabled}"/>
                <p:inputText id="nationality" value="#{customerbean.customer.nationality}" required="true" requiredMessage="#{text['validation.error.required.nationality']}" readonly="#{customerbean.disabled}" />                                                

                <h:outputLabel for="dob" value="Date of Birth" />
                <h:outputLabel for="address" value="Address" />

                <p:calendar id="dob"  value="#{customerbean.customer.dob}" pattern="ddmmyyyy" readonly="#{customerbean.disabled}" />                
                <p:inputText id="address"  value="#{customerbean.customer.address}" readonly="#{customerbean.disabled}" />                               

                <h:outputLabel for="mailingaddress" value="Mailing Address" />
                <h:outputLabel for="gender" value="Gender" />

                <p:inputText id="mailingaddress" value="#{customerbean.customer.mailingAddress}" readonly="#{customerbean.disabled}" />                                                            

                <p:selectOneMenu id="gender" value="#{customerbean.customer.gender}" required="#{!customerbean.disabled}" requiredMessage="#{text['validation.error.required.gender']}" disabled="#{customerbean.disabled}">                      
                    <f:selectItem itemLabel="Select One" itemValue="" noSelectionOption="true" />  
                    <f:selectItem itemLabel="Male" itemValue="Male" />  
                    <f:selectItem itemLabel="Female" itemValue="Female"  />  
                </p:selectOneMenu>              

                <h:outputLabel for="mobileno" value="Mobile No."  />
                <h:outputLabel for="faxno" value="Fax No." />

                <p:inputText id="mobileno"  value="#{customerbean.customer.mobileno}" required="true" requiredMessage="#{text['validation.error.required.mobileno']}" validatorMessage="#{text['validation.error.mobileno']}" readonly="#{customerbean.disabled}" >
                    <f:validateLongRange minimum="0" maximum="99999999999999" />
                </p:inputText>
                <p:inputText id="faxno"  value="#{customerbean.customer.faxno}" readonly="#{customerbean.disabled}" />                

                <h:outputLabel for="otherno" value="Other No." />                
                <h:outputLabel for="primaryemail" value="Primary email" />              

                <p:inputText id="otherno"  value="#{customerbean.customer.otherno}" readonly="#{customerbean.disabled}" />
                <p:inputText id="primaryemail"  value="#{customerbean.customer.primaryemail}" required="false" validatorMessage="#{text['validation.error.required.email']}" readonly="#{customerbean.disabled}">                   
                    <f:validateRegex pattern="([\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z])?" />
                </p:inputText>    

                <h:outputLabel for="alternativeemail" value="Alternative email" />              
                <p:inputText id="alternativeemail"  value="#{customerbean.customer.alternativeemail}" required="false" validatorMessage="#{text['validation.error.required.email']}" readonly="#{customerbean.disabled}">                   
                    <f:validateRegex pattern="([\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z])?" />
                </p:inputText>                    

                <h:outputLabel for="maritalstatus" value="Marital status" />
                <h:outputLabel for="nochildren" value="No. of Children" />                

                <p:selectOneMenu id="maritalstatus" value="#{customerbean.customer.maritalStatus}" disabled="#{customerbean.disabled}">  
                    <f:selectItem itemLabel="Select One" itemValue="" />  
                    <f:selectItem itemLabel="Single" itemValue="Single" />  
                    <f:selectItem itemLabel="Married" itemValue="Married"/>  
                    <f:selectItem itemLabel="Divorced" itemValue="Divorced"/>  
                    <f:selectItem itemLabel="Widow" itemValue="Widow"/>  
                </p:selectOneMenu>  

                <p:inputText id="nochildren"  value="#{customerbean.customer.nochildren}" readonly="#{customerbean.disabled}" />                

                <f:facet name="footer">  
                    <center>
                        <p:commandButton action="#{customerbean.add(customerbean.customer)}" ajax="false" value="Save" icon="ui-icon-check" />

                        <p:commandButton value="Reset" update="cpr passportno name nationality dob address mailingaddress gender genderhidden mobileno faxno otherno primaryemail alternativeemail maritalstatus maritalstatushidden nochildren messages" process="@this"  
                                         icon="ui-icon-cancel">  
                            <pe:resetInput for="cpr passportno name nationality dob address mailingaddress gender genderhidden mobileno faxno otherno primaryemail alternativeemail maritalstatus maritalstatushidden nochildren"/>  
                        </p:commandButton>              
                    </center>
                </f:facet>  
            </p:panelGrid>  
                            <p:inputText id="genderhidden" type="hidden" value="#{customerbean.customer.gender}" />
                            <p:inputText id="maritalstatushidden" type="hidden" value="#{customerbean.customer.maritalStatus}" />
        </ui:define>

    </ui:composition> 

</html>
4

2 に答える 2

0

customerbean を@ViewScopedに設定

例えば:

@ManagedBean
@ViewScoped
public class customerbean implements Serializable {

}
于 2012-09-23T07:00:14.100 に答える
0

わかりました、犯人を見つけました: f:selectItem の noSelectionOption="true" です。それを削除すると、正常に動作します。maritalStatus が機能した理由は、noSelectionOption 属性がないためです。

于 2012-09-26T06:20:38.273 に答える