2012-11-05 2 views
0

클릭하면 목록에 몇 가지 값을 추가해야하는 클릭 수가 p:commandButton입니다. 내 관리 Bean에서 추가해야하는 값의 유효성을 검사하고 false로 확인되면 확인 팝업을 표시해야한다. 조건에 따라 버튼 클릭시 확인 팝업을 표시합니다.

<p:commandButton id="add" value="Add" type="submit"          action="#{bean.doAdd}" ajax="false" 
update=":List"/> 

그리고 빈에서

, "추가"버튼을 클릭에, 내가 JSF 2.0을 사용하고 3.0 primefaces있어

public String doAdd() throws Exception { 
     if(response != null) { 
      if(keyList.contains(response)) { 
       if(!responseList.contains(response)) { 
        responseList.add(response); 
       } 
      } else { 
       //Have to display confirmation popup. 
      } 
      response = ""; 
     } 

     return response; 
    } 

- 이건 내 코드입니다. 누군가 콩에서 팝업을 표시하는 방법을 알려주시겠습니까?

답변

2

당신은

는 Ajax 호출해야합니다 귀하의 관리 빈 내부에 JS 코드를 실행할 수 RequestContext을 사용할 수 있습니다 -이

RequestContext context = RequestContext.getCurrentInstance(); 
context.execute("YourDialogwidgetVar.show()"); 

같은 더 ajax="false"

없어 난 당신이 어떤 대화가 정의되어있어 가정 ...

<p:confirmDialog id="confirmDialog" message="Hello" 
       header="Header" widgetVar="YourDialogwidgetVar"> 
</p:confirmDialog> 
+0

프로젝트에 기본 요소가 포함되어 있습니까? 'import org.primefaces.context.RequestContext;'를 빈에 추가하십시오 ... – Daniel

+0

나는 primefaces를 포함하고, 이전에 잘못된 import를 사용했습니다. 그것을 수정하고 제안한 것을 시도했지만 null 포인터 예외가 발생합니다. – Raaz

+0

은 관리 빈인 bean입니까? '@ManagedBean @ SessionScoped' – Daniel

0

당신에게 도움이됩니다.

private boolean valid = true; 

public void doAdd() { 
    valid = false; 
} 


<p:dialog id="basicDialog" header="Basic Dialog" visible="#{!testBean.valid}"> 
    <h:outputText value="Message!" /> 
</p:dialog> 

<h:commandButton id="modalDialogButton" value="Modal" action="#{testBean.doAdd}"/> 
관련 문제