0

私のページには、ui:include を介して含めるログイン ヘッダーが含まれています。含まれているページには、ap:commandButton を含むダイアログが含まれています。ユーザーがログインすると、update 属性の @form に従ってインクルード ページが適切に更新されます。また、ユーザーがログインしたときにボタンを表示する、インクルードされたページの外部にあるコンポーネントを更新したいと考えています。インクルード ページが更新され、ログインしているユーザーの名前が表示されます。ただし、メイン ページのボタンは表示されません。ただし、ページを更新すると表示されます。ここで何が間違っているのかわかりません。誰でもアイデアはあります。

ヘッダー ページにも、commandLink コンポーネントが適切に表示されます。ただし、ログアウト リンクをクリックしても、メイン ページのボタンは削除されません。commandLink は ajax を使用していないため、通常のページ POST が行われると想定しています。ページ全体をリロードする必要があります。ui:include で参照されているページからは動作しませんか?

ログイン ページは、セッション スコープのバッキング Bean を使用しています。メイン ページはビュー スコープです。

含まれている xhtml (login.xhtml) は次のとおりです。

<ui:composition
    xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui" 
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <div style="width:100%;font-size:12px;line-height:20px;background-color:#b0d9e6;color:white">

<h:form>
<h:message id="top_msg"></h:message>
    <h:panelGrid width="100%" columns="3" columnClasses="none,right1,right1">
       <h:outputLink rendered="#{!loginController.loggedIn}" styleClass="text-align:right;" value="javascript:void(0)" onclick="PF('dlg').show();" title="login">
             <p:outputLabel>Login</p:outputLabel>
        </h:outputLink>


    <h:commandLink rendered="#{loginController.loggedIn}" action="#{loginController.logout}" styleClass="text-align:right;" >
         <h:outputLabel>Logout</h:outputLabel>
    </h:commandLink>

    <p:growl id="growl" sticky="true" showDetail="true" life="3000" />

    <p:dialog header="Login" widgetVar="dlg" resizable="false">
        <h:panelGrid columns="2" cellpadding="5">
            <h:outputLabel for="username" value="Username:" />
            <p:inputText id="username" value="#{loginController.username}" required="true" label="username" />

            <h:outputLabel for="password" value="Password:" />
            <p:password id="password" value="#{loginController.password}" required="true" label="password" />

            <f:facet name="footer">
                <p:commandButton value="Login" 
                        update="@form :createform:createbutton"
                        actionListener="#{loginController.login}"
                        oncomplete="handleLoginRequest(xhr, status, args)" >

                </p:commandButton>
            </f:facet>  
        </h:panelGrid>
    </p:dialog>
    </h:panelGrid>
<script type="text/javascript">
    function handleLoginRequest(xhr, status, args)


</script>

</h:form>

</div>

</ui:composition>
...

これは、次のメイン ページに含まれています。

...
<ui:include src="login.xhtml" />

   <h:form id="createform">
   <h:panelGroup id="createbutton" layout="block">

     <p:commandButton id="createnew"
        ajax="false" 
        action="#{recepieController.createNewRecipes}" 
        value="Create new recipe" 
        rendered="#{recepieController.loggedIn and !recepieController.create and !recepieController.viewOnly and !recepieController.edit}"
        accesskey="s">
      </p:commandButton>
 </h:panelGroup>     
  </h:form>
4

2 に答える 2

2

レンダリングされていないコンポーネントを再レンダリングすることはできません。ボタンを部分的にレンダリングし、ボタンがレンダリングされていない場合、そのボタンは DOM に存在しないため、更新を呼び出すことはできません。

常にレンダリングされる親ネーミング コンテナーで AJAX 更新を呼び出す必要があります。したがって、内部のボタンではなく、 :createformを更新します。フォームは常にレンダリングされます。

于 2016-05-17T20:30:18.807 に答える
0

問題が見つかりました。コマンドボタンの「createnew」で、レンダリングに間違った値を使用しました。

 <p:commandButton id="createnew"
    ajax="false" 
    action="#{recepieController.createNewRecipes}" 
    value="Create new recipe" 
    rendered="#{recepieController.loggedIn and !recepieController.create and !recepieController.viewOnly and !recepieController.edit}"
    accesskey="s">
  </p:commandButton>

ユーザーがログインしているかどうかを確認するには、セッション スコープ Bean (loginController) を使用する必要があります。次のように変更すると機能します。

  <h:panelGroup id="createbutton">
     <p:commandButton id="createnew"
        ajax="false" 
        action="#{recepieController.createNewRecipes}" 
        value="Create new recipe" 
        rendered="#{loginController.loggedIn and !recepieController.create and !recepieController.viewOnly and !recepieController.edit}"
        accesskey="s">
      </p:commandButton>
    </h:panelGroup>

render ="#{recepieController.loggedIn}" ではなく、render="#{loginController.login ...}の違いに注意してください。

recepieController には、設定した loggedIn 属性もありますが、ページが再投稿されていないため、ログイン時に属性の値が変更されていないと思います。ただし、ログイン ダイアログの p:commandButton で ajax="false" を使用するようにテストしたと思います。これにより、loggedIn 属性のビュー スコープ バージョンがリセットされるはずです。なぜそれがうまくいかなかったのか、私にはよくわかりません。

于 2016-05-19T17:05:46.753 に答える