gpt4 book ai didi

java - 如何在 JSF 2.0 中为一键操作设置两个 ajax 事件

转载 作者:太空宇宙 更新时间:2023-11-04 08:09:34 26 4
gpt4 key购买 nike

我必须实现一个场景,例如更改图像并相应地显示文本。意味着同时有两个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请求同时做两项工作?芒 bean :

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");}}

最佳答案

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

通过编写类似 <f:ajax event="action" render="rootImage ViewId"> 的代码解决了这个问题而不是两个单独的ajax请求。

关于java - 如何在 JSF 2.0 中为一键操作设置两个 ajax 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11468901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com