2013-12-19 1 views
0

여기에서 요점을 놓치고 있습니다. 나는JSF 2.0을 사용한 암시 적 탐색에서 다중 결과

<navigation-rule> 
    <from-view-id>/products/DeleteItem.xhtml</from-view-id> 
    <navigation-case> 
     <from-outcome>itemDeleted</from-outcome> 
     <to-view-id>/products/Success.xhtml</to-view-id> 
    </navigation-case> 
    <navigation-case> 
     <from-outcome>itemNotExist</from-outcome> 
     <to-view-id>/products/Failure.xhtml</to-view-id> 
    </navigation-case> 
</navigation-rule> 

그러나 어떻게 암시 적 탐색과 같은 일을 달성 할 수있다 : 나는 명시 적 탐색을 사용하여 예를 들어, 암시 적 탐색 를 사용하여 JSF 2.0의 여러 결과와 요청을 처리 할 수있는 방법은 다음과 같은 기록 할 수 있습니다

<h:link value="Delete a Product" outcome="Success" /> 

하나의 사건이 언급하지만 Success.xhtml 또는 Failure.xhtml이 결과에 따라에 하나를 전달할되어 다음과 같은 노력했다.

암시 적 탐색을위한 몇 가지 추가 정보입니다.

관리 콩 :

import javax.ejb.EJB; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.RequestScoped; 

@ManagedBean 
@RequestScoped 
public class DeletionBean { 
@EJB 
private app.session.ProductFacade ejbProductFacade; 


private int id=0; 


public DeletionBean() { 
} 

public int getId() { 
    return id; 
} 

public void setId(int id) { 
    this.id = id; 
} 

public String deleteProduct(){ 
    String result; 
    result=ejbProductFacade.deleteItem(id); 

    if(result.equals("success")) 
    { 
     status="Successfully performed"; //msg to be shown 

     return "product/DeleteItem"; 
    } 

    else return "product/Failure"; 
} 

} 

양식 :

<h:form> 
       <table border="1" width="5" cellspacing="1" cellpadding="1"> 

         <tr> 
          <td> Product ID </td> 

          <td> 

           <h:inputText id="pid" size="10" value="#{deletionBean.id}" title="Product ID" required="true" requiredMessage="Product ID required"/> 
          </td> 
         </tr> 

         <tr> 

          <td colspan="2"> 
          <h:commandLink value="Delete" action="#{deletionBean.deleteProduct}" /> 
          </td> 

         </tr> 

       </table> 

      </h:form> 

현재 오류 메시지 : 일치하는 탐색 케이스를 찾을 수 없습니다

와에서보기-ID '/product/DeleteItem.xhtml'당신이 당신의 제품을 삭제하는 action 방법을 수행합니다 치죠 결과 '제품/실패'

답변

2

와 행동 '# {deletionBean.deleteProduct}'에 대한, 메소드가 원하는 결과를 리턴하도록해야합니다. JSF 2 사용, 결과의 ID를 사용하여 필요도 당신이 당신의 얼굴-config.xml 파일에 파일, JSF 관계 특정 페이지에 제공된 결과를 선언 할 수 있습니다, 더 이상 없다 :

<h:commandLink action="#{bean.deleteProduct(product)}" 
    value="Delete product" /> 
public String deleteProduct(Product p){ 
    //Try to delete the product and return "products/xxx", 
    //which will be converted to "/contextname/products/xxx.xhtml" 
    try{ 
     daoService.delete(p); 
     return "/products/Success"; 
    catch(Exception e){ 
     return "/products/Failure"; 
    } 
} 

을 그 POST 서버가 동작하고 HTML 양식 제출 버튼처럼 동작합니다 (그 이유는 commandLink입니다). 당신은 단지 가 특정보기에을 GET 수행 할 그럼에도 불구하고, 당신은 결과에 해당 뷰 ID를 사용할 수 있습니다 또한

<h:link value="Go to success doing nothing" 
    outcome="/products/Success" /> 

참조 :

Implicit navigation in JSF 2

+0

감사 @Xtreme 자전거 빠른 응답을 위해 언급 한대로 수정했지만 다음과 같은 오류 메시지가 나타납니다. –

+0

전체 경로로 시도하십시오. 내 대답을 편집했습니다. –

+0

빠른 응답을 위해 @Xtreme Biker 감사합니다. 언급 한대로 수정했지만 다음 오류 메시지가 나타납니다. ** 결과 'product/Failure'로 액션 '# {deletionBean.deleteProduct}'에 대해 from-view-id '/product/DeleteItem.xhtml'과 일치하는 탐색 케이스를 찾을 수 없습니다 ** –