0

我有以下代码:

<h:form id="facebookForm">
    <p:button value="Facebook Connect" href="#{loginPageCode.facebookUrlAuth}">  
          <p:ajax event="click" listener="#{loginPageCode.getUserFromSession}" update="growl confirmDialog" ></p:ajax>
    </p:button>

    <p:confirmDialog id="confirmDialog" message="Welcome"
                        header="Welcome to our website!" severity="alert" widgetVar="confirmation">
         <h:panelGrid columns="1" cellpadding="10">
                            <h:outputText id="msg" value="Salutation : #{user.salutation}" />
                            <h:outputText id="msg1" value="Name and surname: #{user.name} #{user.surname}" />
                            <h:outputText id="msg2" value="Birthday : #{user.birthDate}" />
                            <h:outputText id="msg3" value="Email : #{user.email}" />
                            <h:outputText id="msg4" value="Postal code : #{user.postalCode}" />
                            <h:outputText id="msg5" value="Phone nr : #{user.phoneNumber}" />
         </h:panelGrid>
         <p:commandButton id="confirmation" value="Ok" onclick="confirmation.hide()" type="button" />
    </p:confirmDialog>

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

</h:form>

我正在尝试通过自定义从我的网页连接到facebookservlet ,该自定义处理有关验证、解析响应等的所有内容。href上面的表单包含指向 facebook 身份验证的 url,最终将所有内容重定向到当前页面,其中是index.xhtml

我想要做的是在一切完成后调用一个方法,比如onComplete来自组件的属性<p:commandButton>,因为我想显示一个带有更新的托管 bean 的对话框<p:confirmDialog>,并欢迎。所以我需要首先转到第一个URL,等到身份验证完成,然后调用这个方法#{loginPageCode.getUserFromSession},通过从 facebook http 响应解析 JSON,动态更新托管 bean,然后打开包含更新值的对话框。

我也尝试过使用<p:commandButton>withtype="button"来使用action//能力actionListenerupdate但不成功。你能给些建议么?谢谢你。

4

2 回答 2

1

基本上,您需要在后面进行大部分处理。试试这个

  1. 定义一个preRenderView事件,您将在其中完成大部分 facebook 登录的后处理。此事件将在index.xhtml中定义。你的代码看起来像这样

    <f:metadata>
      <f:event type="preRenderView" listener="#{loginPageCode.postFBProcessing}" />
    </f:metadata>
    

    postFBProcessing中,您将执行从 FB 返回后需要执行的任何处理(处理 JSON 响应、从会话中获取用户等)。

  2. dialogVisible在您的支持 bean 中定义一个布尔值并将<p:dialog/>'visible属性绑定到变量或用于RequestContext更新对话框。

    <p:confirmDialog id="confirmDialog" message="Welcome" visible="#{loginPageCode.isDialogVisible}" header="Welcome to our website!" severity="alert" widgetVar="confirmation">
    
于 2013-02-20T13:18:10.050 回答
1

您过度思考/误解了 HTTP 和 ajax 的一般工作方式。在同步 GET 请求上不可能有一个 ajax oncomplete 钩子。

index.xhtml只需根据您在index.xhtml回调 URL中指定的某些特定请求参数,在与 FB 身份验证最终重定向到的相关联的请求/视图范围的(后)构造函数中完成这项工作。

于 2013-02-23T13:05:23.883 回答