JSF ajax不更新表单

时间:2014-02-15 14:28:27

标签: ajax jsf

我正在编写一个用户可以更改其帐户设置的页面。还有他的密码 但我不想显示他可以随时输入新密码的字段 所以我点击这个命令按钮“更改密码”,新密码的输入字段应该显示出来。我使用了c:if if that that。单击该按钮时,我在ManagedBean中设置一个布尔值showPasswordFields为true。这有效。但是使用ajax更新页面不起作用 我在commandButton中使用了这一行来更新整个表单:

<p:ajax update=":formUserSettings" />

这是我的页面:

<?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:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core">

    <h:body>

        <ui:composition template="/META-INF/templates/templateContentOne.xhtml">

            <ui:define name="title">
                <h:outputText value="User-Settings" />
            </ui:define>

            <ui:define name="content">
                <h:form id="formUserSettings">

                    <p:tabView id="TabViewUserSettings">
                        <p:tab title="Account" id="TabAccount">
                            <p:panelGrid>
                                <p:row>
                                    <p:column>
                                        <h:outputLabel value="User-No" />

                                    </p:column>
                                    <p:column>
                                        <p:inputText value="#{userSettingBean.user.ID}" />
                                    </p:column>
                                </p:row>
                                <p:row>
                                    <p:column>
                                        <h:outputLabel value="E-Mail" />
                                    </p:column>
                                    <p:column>
                                        <p:inputText value="#{userSettingBean.user.EMAIL}" />
                                    </p:column>
                                </p:row>




                                <p:row>
                                    <p:column>
                                        <h:outputLabel value="Password" />
                                    </p:column>
                                    <p:column>
                                        <p:commandButton id="commandButtonChange Password" value="Change Password" 
                                        actionListener="#{userSettingBean.enablePasswordFields}" immediate="true">
                                           <p:ajax update=":formUserSettings" />
                                        </p:commandButton>
                                    </p:column>

                                </p:row>



                                <c:if test="#{userSettingBean.showPasswordFields}">

                                    <p:row id="RowConfirmOldPw">
                                        <p:column>
                                            <p:inputText id="oldPwd"
                                                value="#{userSettingBean.oldPassword}" />
                                            <p:watermark for="oldPwd" value="Old Password" />
                                        </p:column>
                                    </p:row>



                                    <p:row id="RowTypeNewPassword">

                                        <p:column>
                                            <p:password id="pwd1" value="#{userSettingBean.password1}" match="pwd2" lable="New Password"/>
                                            <p:watermark forElement="pwd1" value="Password" />
                                        </p:column>
                                        <p:column>
                                            <p:password id="pwd2" value="#{userSettingBean.password2}" lable="Re-enter"/>
                                            <p:watermark forElement="pwd2" value="Re-Enter" />
                                        </p:column>
                                    </p:row>


                            </c:if>


                                <p:row>
                                    <p:column>
                                        <h:outputLabel value="Title" />
                                    </p:column>
                                    <p:column>
                                        <p:inputText value="#{userSettingBean.user.TITLE}" />
                                    </p:column>
                                </p:row>

                                <p:row>
                                    <p:column>
                                        <h:outputLabel value="Degree" />
                                    </p:column>
                                    <p:column>
                                        <p:inputText value="#{userSettingBean.user.DEGREE}" />
                                    </p:column>
                                </p:row>

                                <p:row>
                                    <p:column>
                                        <h:outputLabel value="Name" />
                                    </p:column>
                                    <p:column>
                                        <p:inputText id="firstname" value="#{userSettingBean.user.FIRST_NAME}"/>
                                        <p:watermark for="firstname" value="Firstname" />
                                    </p:column>
                                    <p:column>
                                        <p:inputText id="lastname" value="#{userSettingBean.user.LAST_NAME}"/>
                                        <p:watermark for="lastname" value="Lastname" />
                                    </p:column>
                                </p:row>

                                <p:row>
                                    <p:column>
                                        <h:outputLabel value="Birthday" />
                                    </p:column>
                                    <p:column>
                                        <p:inputText value="#{userSettingBean.user.BIRTHDAY}"/>
                                    </p:column>
                                </p:row>



                                <p:row>
                                    <p:column>
                                        <p:commandButton style="float: left;" value="Save" actionListener="#{userSettingBean.saveChanges}"/>
                                    </p:column>
                                </p:row>


                            </p:panelGrid>

                        </p:tab>







                        <p:tab title="Contact">
                        <p:panelGrid>
                            <p:row>
                                <p:column>
                                    <h:outputLabel value="Street Name" />
                                </p:column>
                                <p:column>
                                    <p:inputText value="#{userSettingBean.user.STREET_NAME}"/>
                                </p:column>
                            </p:row>
                            <p:row>
                                <p:column>
                                    <h:outputLabel value="Street No." />
                                </p:column>
                                <p:column>
                                    <p:inputText value="#{userSettingBean.user.STREET_NO}"/>
                                </p:column>
                            </p:row>
                            <p:row>
                                <p:column>
                                    <h:outputLabel value="ZIP" />
                                </p:column>
                                <p:column>
                                    <p:inputText value="#{userSettingBean.user.ZIP}"/>
                                </p:column>
                            </p:row>
                            <p:row>
                                <p:column>
                                    <h:outputLabel value="City" />
                                </p:column>
                                <p:column>
                                    <p:inputText value="#{userSettingBean.user.CITY}"/>
                                </p:column>
                            </p:row>

                            <p:row>
                                <p:column>
                                    <h:outputLabel value="State" />
                                </p:column>
                                <p:column>
                                    <p:inputText value="#{userSettingBean.user.STATE}"/>
                                </p:column>
                            </p:row>
                            <p:row>
                                <p:column>
                                    <h:outputLabel value="Country" />
                                </p:column>
                                <p:column>
                                    <p:inputText value="#{userSettingBean.user.COUNTRY}"/>
                                </p:column>
                            </p:row>
                            <p:row>
                                <p:column>
                                    <h:outputLabel value="Fixed Line" />
                                </p:column>
                                <p:column>
                                    <p:inputText value="#{userSettingBean.user.FIXED_LINE}"/>
                                </p:column>
                            </p:row>
                            <p:row>
                                <p:column>
                                    <h:outputLabel value="Mobil Phone" />
                                </p:column>
                                <p:column>
                                    <p:inputText vlaue="#{userSettingBean.user.MOBILE_PHONE}"/>
                                </p:column>
                            </p:row>

                            <p:row>
                                <p:column>
                                    <h:outputLabel value="Fax" />
                                </p:column>
                                <p:column>
                                    <p:inputText value="#{userSettingBean.user.FAX}"/>
                                </p:column>
                            </p:row>

                            <p:row>
                                <p:column>
                                    <p:commandButton style="float: left;" value="Save" actionListener="#{userSettingBean.saveChanges}"/>
                                </p:column>
                            </p:row>

                        </p:panelGrid>

                        </p:tab>
                    </p:tabView>


                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>

</html>

1 个答案:

答案 0 :(得分:0)

我看到页面中只有一个表单,因此您可以使用@form标记。替换你的

<p:ajax update=":formUserSettings" />

用这个:

<f:ajax execute="@form" render="@form" />