1

我必须实现一个场景,比如更改图像并相应地显示文本。意味着同时有两个 ajax ......所以我正在编写这样的代码,但图像正在改变并且它正在工作但文本没有显示。刷新该页面后出现文本,即文本被替换但未显示..... 代码为:

<h:commandLink class="SampleImageCSS">
            <h:graphicImage id="sample2" alt="No iamge to display"
                value="#{carDetails.carUrl2}" height="100" width="100"
                title="Car For Beeding" />
            <f:setPropertyActionListener target="#{carDetails.rootImage}"
                value="#{carDetails.carUrl2}" />
                <f:setPropertyActionListener target="#{carDetails.view}" 
                value="#{carDetails.viewDetails['carUrl2']}" />
            <f:ajax event="action" render="rootImage">
            </f:ajax>
            <f:ajax event="action" render="ViewId">
            </f:ajax>
        </h:commandLink>

如何触发ajax请求同时做两项工作?豆角:

public class CarDetails {

  private int id;
  private String carUrl1;
  private String carUrl2;
  private String carUrl3;
  private String carUrl4;
  private String carUrl5;
  private String carUrl6;
  private String view;
  public String getView() {
    return view;
}
public void setView(String view) {
    this.view = view;
}
  HashMap<String, String> viewDetails = new HashMap<String, String>();

  public HashMap<String, String> getViewDetails() {
    return viewDetails;
}
public void setViewDetails(HashMap<String, String> viewDetails) {
    this.viewDetails = viewDetails;
}
//other getter setter
public CarDetails(){
  carUrl1="http://www.screamingtiger.com/images/car1.jpg";
  carUrl2="http://www.allbestwallpapers.com/tagwallpaper/convertible%20car-wallpapers.jpg";
  carUrl3="http://media.treehugger.com/assets/images/2011/10/ec-rnd-005.jpg";
  carUrl4="http://www.urbadriver.com/wp-content/uploads/2010/12/car.jpg";
  carUrl5="http://www.businessfinancemag.info/wp-content/uploads/2011/01/car_loans.jpg";
  carUrl6="http://cars-wallpapers.eu/images/Old_cars/00000018.jpg";
  rootImage="http://www.screamingtiger.com/images/car1.jpg";

  viewDetails.put("carUrl1", "Front view");
  viewDetails.put("carUrl2", "Right Side View");
  viewDetails.put("carUrl3", "Top or Plan View");
  viewDetails.put("carUrl4", "Rear view");
  viewDetails.put("carUrl5", "Back view");
  viewDetails.put("carUrl6", "Bottom View");}}
4

1 回答 1

1

一些谷歌得到它后的简单...

通过编写代码<f:ajax event="action" render="rootImage ViewId">而不是两个单独的ajax请求来解决它。

于 2012-07-13T11:07:57.597 回答