2012-04-09 49 views
0

使用JSF + PrettyFaces处理导航和bean操作时,Java Web App出现问题。JSF2 <h:selectOneMenu和<f:在PrettyFaces过滤器导航后未调用的<ajax侦听器

使用的版本:

JSF - 2.1
PrettyFaces - 使用PrettyFaces从链接过滤处理导航时3.3.3

错误发生的情况:

   <div class="product_img"> 
       <pretty:link mappingId="viewProduct"> 
        <img src="#{request.contextPath}/image?id=#{product.mainImage.fileReference.id}" />            
        <f:param value="#{productMB.filters.productCategoryName}" /> 
        <f:param value="#{product.name}" />                   
       </pretty:link>             
      </div>               

漂亮,配置.xml映射是:

<url-mapping id="viewProduct"> 
     <pattern value="/shop/product/#{ productCategoryName : productMB.filters.productCategoryName }/#{ productName : productMB.filters.productName }/" /> 
     <view-id value="/pages/productDetails.faces" /> 
     <action>#{productMB.openProductDetails}</action> 
    </url-mapping> 

豆动作:

public String openProductDetails() { 

    if (filters.getProductCategoryName() != null && !filters.getProductName().equals("")) {   
     loadProductDetailsByName(filters.getProductCategoryName()); 
    } 

    return "/pages/productDetails.faces"; 
} 

在产品详细信息页用户土地,在那里他可以选择的产品特点如颜色,大小等...

<ui:fragment rendered="#{productMB.productVO.featureColorAvailable}"> 
     <span class="productFeatureLabel">#{msg.color}</span> 

     <h:selectOneMenu id="colorSelect" 
      value="#{productMB.productVO.colorSelected}" 
      valueChangeListener="#{productMB.colorSelectedValueChanged}"> 
      <f:selectItem itemLabel="#{msg['select']}" noSelectionOption="true" /> 
      <f:selectItems value="#{productMB.productFeatureAvailableApplMap['color']}" var="colorItem" itemValue="#{colorItem}" 
       itemLabel="#{msg[colorItem.name]}" /> 
      <f:ajax event="valueChange"    
      listener="#{productMB.colorSelectedValueChanged}" 
       render="@this productDetailImage productSubImage productSubImage2 productSubImage3 sizeSelect"></f:ajax> 
     </h:selectOneMenu>  
    </ui:fragment> 

// ...豆类动作方法

public void colorSelectedValueChanged(ValueChangeEvent event) { 

     if (null != event.getNewValue()) { 
      ProductFeatureAppl prodFeatureAppl = (ProductFeatureAppl) event.getNewValue(); 
      filterProductFeatureSelectItem(AppConstants.SIZE, prodFeatureAppl.getProductFeature().getName()); 
     } else { 
      filterProductFeatureSelectItem(AppConstants.SIZE, null); 
     } 
    } 

    public void colorSelectedValueChanged(AjaxBehaviorEvent event) throws javax.faces.event.AbortProcessingException { 

     try { 
      if (null != productVO.getColorSelected()) { 
       ProductFeatureAppl prodFeatureAppl = productVO.getColorSelected(); 
       filterProductFeatureSelectItem(AppConstants.SIZE, prodFeatureAppl.getProductFeature().getName()); 

       String prodFeatName = prodFeatureAppl.getProductFeature().getName(); 

       // switch selected pics. 
       productVO.setCurrentDetailImageName(productVO.getProduct().getProductImageByTypeAndFeatureName(
         NameConstants.DETAIL, prodFeatName).getFileReference().getId()); 

       productVO.setCurrentBigImageName(productVO.getProduct().getProductImageByTypeAndFeatureName(
         NameConstants.BIG, prodFeatName).getFileReference().getId()); 

      } else { 
       filterProductFeatureSelectItem(AppConstants.SIZE, null); 
       filterProductFeatureSelectItem(AppConstants.COLOR, null); 

       // reset to default 
       productVO.setCurrentDetailImageName(productVO.getProduct().getProductImageByType(ProductImageType.DETAIL1.toString()).getFileReference().getId()); 
       productVO.setCurrentBigImageName(productVO.getProduct().getProductImageByType(ProductImageType.BIG1.toString()).getFileReference().getId());             
      }  

     } catch (Exception ex) { 
      addErrorMessage(getMessage("error")); 
      if (screenComponent.isDisplayException()) { 
       addErrorMessage(ex.getMessage()); 
      } 
     } 

    } 

第一导航,产品详细信息页面之后,每当选择从 selectOneMenu用于ID = “colorSelect” 的valueChangeListener和AJAX听者的值不被调用。除此之外,调用productMB.openProductDetails操作。

ajax调用完成,没有错误,我可以在日志中看到,但没有监听器方法被调用。 有人知道为什么这些JSF Ajax侦听器被跳过吗?

在此先感谢。

回答

1

如果您直接从URL访问页面,页面是否可以正常工作?如果PrettyFaces被禁用,它会起作用吗?

我怀疑这是链接或PrettyFaces的问题。我敢打赌,它与AJAX和部分状态保存有关。

这可能是因为它与此有关:

public String openProductDetails() { 
    if (filters.getProductCategoryName() 
      != null && !filters.getProductName().equals("")) {   
     loadProductDetailsByName(filters.getProductCategoryName()); 
    } 

    return "/pages/productDetails.faces"; // why is this being returned? 
} 

你在那里返回页面名称。 PrettyFaces实际上可能试图在这个String上导航。如果您希望显示您在映射中配置的页面,只需返回null,返回空字符串或不返回任何内容。

希望这会有所帮助。

+0

我改变了方法返回null;现在调用监听器,但仍在HTTP POST POST Ajax请求的JSF生命周期中调用productMB.openProductDetails()。我试着改变:\t \t Pretty Filter \t com.ocpsoft.pretty.PrettyFilter \t \t false \t \t \t 为true和false,但都没有解决。我还尝试更改PrettyFilter的过滤器映射,以包含ASYNC和INCLUDE的调度程序,但添加这些或删除并不能解决问题。 – guilhebl 2012-04-10 20:33:18

+0

我发现productMB.openProductDetails在任何ajax请求之后被调用的原因,我添加了#{productMB.openProductDetails}。我相信我将不得不对所有具有ajax组件的页面使用onPostback = false。你知道这是否是关于Ajax调用和PrettyFaces的正确说法吗?提前致谢。 – guilhebl 2012-04-10 21:11:14

+0

是的,这是正确的,因为JSF AJAX请求实际上使用HTTP POST。 – Lincoln 2012-04-12 21:19:22