我有一个简单的登录表单。当我单击Login时,a4j:commandButton工作正常,并且包含登录表单的位置变成了带有注销的用户信息链接。但是,当我单击Logout链接时,ajax只显示状态,但是如果我再次单击它,什么也不会发生,用户将被注销,这正是我想要的
这意味着我必须单击两次才能注销用户?发生了什么?
<a4j:outputPanel id="login_wrapper" ajaxRendered="true">
<h:form id="fm_logged" rendered="#{mAccount.loggedIn}">
<h3>User Information</h3>
<a4j:status name="login_form_status">
<f:facet name="start">
<h:graphicImage library="images" name="ajax-loader.gif" />
</f:facet>
</a4j:status>
<h6><h:outputText value="Welcome! #{mAccount.acc.name}" /></h6>
<ul class="list1">
<li><h:link value="User Account Control" outcome="/pages/management/buyer_home" style="text-decoration:none;"></h:link></li>
<li><a4j:commandLink id="logout" status="login_form_status" actionListener="#{mAccount.Logout}" value="Logout" style="text-decoration:none;"></a4j:commandLink></li>
</ul>
</h:form>
<h:form id="login-form" class="login-form" rendered="#{!mAccount.loggedIn}" >
<h3>Login Form</h3>
<a4j:status name="login_form_status">
<f:facet name="start">
<h:graphicImage library="images" name="ajax-loader.gif" />
</f:facet>
</a4j:status>
<h:outputText value="Wrong username or password" rendered="#{mAccount.wrongUsername}" style="color:red;" />
<fieldset>
<div class="field">
<label>Email: </label><h:inputText value="#{mAccount.acc.email}" />
</div>
<div class="field">
<label>Password</label><h:inputSecret value="#{mAccount.acc.password}" />
</div>
<div class="field">
<label class="alt">Remember me</label><h:selectBooleanCheckbox value="#{mAccount.rememberMe}" />
</div>
<ul>
<li><h:link outcome="forgot_password">Forgot your password?</h:link>
</li>
<li><h:link outcome="registration">Create an account.</h:link>
</li>
</ul>
<div class="wrapper">
<a4j:commandButton id="login" status="login_form_status" value="Login" actionListener="#{mAccount.Login}"> </a4j:commandButton>
</div>
</fieldset>
</h:form>
</a4j:outputPanel>发布于 2011-07-11 16:55:44
您有两个表单。当一个表单使用ajax重新呈现另一个表单时,另一个表单的视图状态将丢失。在您刷新表单之前,JSF不会处理表单提交(这就是第一次单击所做的事情,因此第二次单击就能正常工作)。
您需要重新排列ajax重新呈现逻辑,以便一个表单不会重新呈现整个另一个表单,而只呈现其内容。因此,使用一个id在另一个<h:form>中添加一些包含组件,然后使用提交表单中的ajax命令链接/按钮的reRender属性引用它。
https://stackoverflow.com/questions/6634541
复制相似问题