int pretty-config.xml
JSF
在进入pretty-config
中指示的视图之前,我需要做一些事情(调用bean方法)。...
<url-mapping id="queryUser">
<pattern value="/queryUser" />
<view-id value="/path/to/queryUser.xhtml" />
</url-mapping>
<url-mapping id="doRegisterTipProcess">
<pattern value="/doRegisterTipProcess" />
<view-id value="HOW_CALL_registerTipBean.redirectQueryUser()_METHOD_BEFORE_queryUser" />
</url-mapping>
<url-mapping id="doRegisterCitProcess">
<pattern value="/doRegisterCitProcess" />
<view-id value="HOW_CALL_registerCitBean.redirectQueryUser()_METHOD_BEFORE_queryUser" />
</url-mapping>
现在,当调用redirectQueryUser
方法时,它指示谁是主叫方,以便与selectedUser
返回以执行某些处理。
@ManagedBean(name = "registerTipBean")
@ViewScoped
public Class RegisterTipBean{
private String selectedUser;
@PostConstruct
public void init() {
selectedUser = Faces.getFlashAttribute("selectedUser");
if (selectedUser !=null) {
System.out.println("RegisterTipBean.selectedUser:" + selectedUser);
}
}
//Indicate where Return TIP
public void redirectQueryUser() {
try {
Faces.setFlashAttribute("whoCall", "RegisterTipBean");
FacesContext.getCurrentInstance().getExternalContext().redirect("queryUser");
} catch (IOException e) {
}
}
}
@ManagedBean(name = "registerCitBean")
@ViewScoped
public Class RegisterCitBean{
private String selectedUser;
@PostConstruct
public void init() {
selectedUser = Faces.getFlashAttribute("selectedUser");
if (selectedUser !=null) {
System.out.println("RegisterCitBean.selectedUser:" + selectedUser);
}
}
//Indicate where Return CIT
public void redirectQueryUser() {
try {
Faces.setFlashAttribute("whoCall", "RegisterCitBean");
FacesContext.getCurrentInstance().getExternalContext().redirect("queryUser");
} catch (IOException e) {
}
}
}
doProcess
方法 QueryUserBean
“搜索” selectedUser
,然后返回Bean调用程序。
@ManagedBean(name = "queryUserBean")
@ViewScoped
public class QueryUserBean {
private String whoCall;
private String selectedUser;
@PostConstruct
public void init() {
whoCall = Faces.getFlashAttribute("whoCall");
}
public void doProcess() {
selectedUser = selectedUser + "found!"
if (Objects.equals(whoCall, "RegisterTipBean")) {
Faces.setFlashAttribute("selectedUser", selectedUser);
try {
FacesContext.getCurrentInstance().getExternalContext().redirect("registerTip");
} catch (IOException e) {
}
}
if (Objects.equals(whoCall, "RegisterCitBean")) {
Faces.setFlashAttribute("selectedUser", selectedUser);
try {
FacesContext.getCurrentInstance().getExternalContext().redirect("registerCit");
} catch (IOException e) {
}
}
}
}
在转到视图之前如何执行该方法?