1

我面临的问题是<p:commandButton>withid="emailav"不调用 action method emailAvailability。我在里面使用它,p:wizard并且我在里面包含了以下代码块h:form

1)xhtml

<p:tab id="personal" title="Personal">
    <p:panel header="Personal Details" style="font-size:small">
        <h:panelGrid columns="3" columnClasses="label, value"
            styleClass="grid">
            <h:outputText value="Username*" />
            <p:inputText id="usrname" required="true" label="Username"
                value="#{registrationBean.user.userName}"
                requiredMessage="Username required" />
            <p:message for="usrname"></p:message>
            <h:outputText value="Firstname: *" />
            <p:inputText id="frstname" required="true" label="Firstname"
                value="#{registrationBean.user.firstName}"
                requiredMessage="Firstname required" />
            <p:message for="frstname"></p:message>
            <h:outputText value="Lastname: *" />
            <p:inputText id="lstname" required="true" label="Lastname"
                value="#{registrationBean.user.lastName}"
                requiredMessage="Lastname required" />
            <p:message for="lstname"></p:message>
            <h:outputText value="Password: *" />
            <p:password id="pwd1" value="#{registrationBean.user.password}"
                feedback="true" match="pwd2" label="Password" required="true"
                requiredMessage="Password required" />
            <p:message for="pwd1"></p:message>
            <h:outputText value="Confirm Password: *" />
            <p:password id="pwd2" value="#{registrationBean.user.password}"
                label="Confirm Password" required="true"
                requiredMessage="Enter the password again" />
            <p:message for="pwd2"></p:message>
            <h:outputText value="Date of Birth(dd/MM/yyyy):" />
            <p:inputText id="dob" label="Date of Birth"
                value="#{registrationBean.user.birthDate}" />
            <p:message for="dob"></p:message>
            <h:outputText value="Gender: " />
            <p:selectOneMenu id="gender" value="#{registrationBean.user.gender}">
                <f:selectItem itemLabel="Select One" itemValue="" />
                <f:selectItem itemLabel="Male" itemValue="Male" />
                <f:selectItem itemLabel="Female" itemValue="Female" />
                <f:selectItem itemLabel="Other" itemValue="Other" />
            </p:selectOneMenu>
            <p:message for="gender"></p:message>
            <h:outputText value="Relationship Status: " />
            <p:selectOneMenu id="relationship"
                value="#{registrationBean.user.relationship}">
                <f:selectItem itemLabel="Select One" itemValue="" />
                <f:selectItem itemLabel="Single" itemValue="Single" />
                <f:selectItem itemLabel="Committed" itemValue="Committed" />
                <f:selectItem itemLabel="Open relationship" itemValue="Open relationship" />
                <f:selectItem itemLabel="Its comlicated" itemValue="Its complicated" />
            </p:selectOneMenu>
            <p:message for="relationship"></p:message>
            <h:outputText value="Email: *" />
            <p:inputText  id="email" label="Email"
                value="#{registrationBean.user.email}" required="true"
                requiredMessage="Email required"/>
            <p:message for="email"/>
            <p:commandButton id="emailav" value="email availability"
                action="#{registrationBean.emailAvailability}" update="emailav" />
            <p:message for="emailav"></p:message>
            <p:commandButton style="display:none"/>
            <h:outputText value="Skip to last: " />
            <h:selectBooleanCheckbox value="#{registrationBean.skip}" />
        </h:panelGrid>
    </p:panel>
</p:tab>

2)背豆

public String emailAvailability() {
        logger.info("inside emailAvailability");
        FacesContext context = FacesContext.getCurrentInstance();
        Query query = em.createQuery("SELECT u FROM User u", User.class);
        List<User> results = query.getResultList();
        Iterator<User> it = results.listIterator();
        while (it.hasNext()) {

            if (it.next().getEmail().equals(user.getEmail())) {
                context.addMessage(null,
                        new FacesMessage("Email already taken"));
            }

        }
         context.addMessage(null, new FacesMessage("Email not taken"));
        return "success";
    }
4

1 回答 1

1

尝试添加 process="@this"

喜欢

                <p:commandButton
                    value="Add Site 1"
                    update="editor"
                    title="Remover"
                    action="#{jobEngine2MB.addSiteType1}"
                    process="@this" />
于 2014-02-23T18:30:49.977 回答