2012-07-27 3 views
3

나는 아래의 코드를 위의 경우h를 실행하는 방법 : onclick하기 전에 commandButton actionListener?

   <h:commandButton id="WhatifButtonID" value="#{demandBean.dmdReviewScreenLabelVO.whatIf}" style="width:60px; height:22px;" actionListener="#{demandBean.whatif}" onclick="window.open('DemandTargetList.xhtml','whatif','width=460,height=280,top=150,left=350,resizable=no,scrollbars=no')" > 
        <f:ajax execute="@this" ></f:ajax> 
       </h:commandButton> 

의 도움이 필요의 온 클릭 속성은 처음의 ActionListener 속성 다음에 실행됩니다. onclick을로드하는 페이지가 actionListener에서 특정 값을 가져와야하기 때문에 actionListener 속성이 onclick 함수 다음에 먼저 실행되도록하고 싶습니다. 같은 것을 달성하는 방법을 알려주십시오. 미리 감사드립니다.

답변

4

<f:ajax>이 완료되면 스크립트를 렌더링합니다. 는 whatif() 방법 true로 설정 whatifPressed 상기

<h:commandButton value="#{demandBean.dmdReviewScreenLabelVO.whatIf}" actionListener="#{demandBean.whatif}"> 
    <f:ajax execute="@this" render="popupScript" /> 
</h:commandButton> 
<h:panelGroup id="popupScript"> 
    <h:outputScript rendered="#{demandBean.whatifPressed}"> 
     window.open('DemandTargetList.xhtml','whatif','width=460,height=280,top=150,left=350,resizable=no,scrollbars=no'); 
    </h:outputScript> 
</h:panelGroup> 

.

+0

빠른 응답을 보내 주신 BalusC에게 감사드립니다. 정말 도움이되었습니다. 그러나 팝업을로드하는 데 걸리는 시간은 조금 더 길어 보인다. 또한 속성이 실행되는 순서를 알려주시겠습니까? 어떤 속성이 먼저 실행되는지 어떻게 알 수 있습니까? – vr3w3c9

+2

HTML/JS가 작동하는 방식을 이해하면 쉽습니다 (기본적으로 JSF가 생성하는 모든 것). 그렇다면 적절한 HTML/JS 자습서를 통해 JSF에서 생성 된 HTML/JS 코드 (브라우저에서 페이지를 오른쪽 클릭하고 * 소스보기 *)를 살펴보면 충분히 명확해야합니다. – BalusC

0

PrimeFaces는 <p:remoteCommand/> 태그를 사용할 때 도움이 될 수 있습니다. 일반 버튼을 사용하여 remoteCommand를 호출 한 다음 window.open()을 실행하면됩니다.

<p:remoteCommand name="viewSomething" actionListener="#{someActionIWantToExecuteBeforeOpeningWindow}" update="@this" process="@this"/> 
<button onclick="viewSomething(); window.open('http://somewhere.com', 'windowName', 'height=924,width=723');">Click me!</button> 

javascript 함수를 호출하면 고유 한 항목을 만들면 항목 목록에 사용할 수 있습니다.