我知道有很多类似的线程,但不像我的:
我有一个 requestscope bean:
@ManagedBean
@RequestScoped
public class Bean implements Serializable{
private String username = ""; //managed by textbox
private String password = ""; //managed by textbox
private String id ="-";
//Load the Parameter as usual:
@PostConstruct
public void fetchParams(){
System.out.println("FETCH PARAMS");
FacesContext facesContext = FacesContext.getCurrentInstance();
String id = facesContext.getExternalContext().getRequestParameterMap().get("id");
if(id == null || id.length() == 0) return;
setId(id);
}
// getters & setters
public void doSomething(){ //executed when clicked on the sumbit-button on the jsf-site
StaticFunctions.doSomething(this);
}
}
代码执行以下操作:它检索获取参数“id”并将其保存到 String id(由 string.out.... 确认)。
但是当执行 doSomething() 方法并读取先前存储的“id”并返回“-”时(就像什么都没发生一样)。
为什么会这样?