I tried all available solutions from net but the command button is not been auto clicked. I am Opening a JSF application from another application on the Link I am passing session id and getting the value stored in redis server against the session id. Everything is working except the auto click of login button The below is UI code is of the Login page which I want to auto redirect to pages in the login () method of UserManagerNew Bean. Please help me solve the issue.
<html>
<body>
<div id="login-overlay" class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Welcome To Adhoc
Reports</h4>
</div>
<div class="modal-body">
<h:graphicImage library="images" name="kccaImg_1581071635760.jpg"/>
<o:form id="login-form" class="form-horizontal" includeRequestParams="true" enctype="multipart/form-data">
<h:commandButton id="submitLogin" value="Login" action="#{userManagerNew.login}" class="btn btn-success col-sm-7"></h:commandButton>
</o:form>
</div>
</div>
</div>
<script>
window.onload = function(){
document.getElementById('submitLogin').click();
}
</script>
</body>
</html>
My Managed Bean is as Below.
@ManagedBean(name = "userManagerNew", eager = true)
@RequestScoped
@Service
public class UserManagerNew {
private String user;
private String password;
private Integer ulbId;
private String key;
String ulbName;
private List<Ulb> ulbs = new ArrayList<>();
String errorTitle;
String errorDetails;
Boolean logine = false;
Manager manager;
private String sessionData;
@Autowired
private GisRedisRepository redisRepository;
@PostConstruct
private void init() throws SQLException {
manager = SpringUtil.getService(Manager.class);
ulbs = manager.getAllULBs();
Map<String, Object> mp = getUserDetails();
}
public Map<String, Object> getUserDetails(){
Integer ADMINULB=9999;
Integer STATEULB=999;
String ADMINCODE="ADMIN";
String STATECODE="KCCA";
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) (facesContext.getExternalContext().getRequest());
if(request.getParameter("key")!=null && !request.getParameter("key").isEmpty()) {
key = request.getParameter("key");
}
String usrDtlsJson =redisRepository.validateLoggedInUser(key);
UserBean loggedUsr = (UserBean) new Gson().fromJson(usrDtlsJson, UserBean.class);
ulbId = loggedUsr.getUlbId().equals(STATEULB)?ADMINULB:STATEULB;
Map<String, Object> mp = new HashMap<>();
mp.put("USERBEAN", loggedUsr);
return mp;
}
public String login() throws SQLException {
Integer ADMINULB=9999;
Integer STATEULB=999;
String ADMINCODE="ADMIN";
String STATECODE="KCCA";
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession)
facesContext.getExternalContext().getSession(false);
UserBean loggedUsr=null;
Map<String, Object> mp = getUserDetails();
UserBean usrBean = (UserBean)mp.get("USERBEAN");
ulbId = usrBean.getUlbId().equals(STATEULB)?ADMINULB:STATEULB;
logine = true;
if(getUlbId() == null || getUlbId() == 0) {
setErrorTitle("ULB Not selected");
setErrorDetails("Please select ULB");
logine = false;
return "Error.xhtml?faces-redirect=true";
}
String ulbname = manager.getUlbName(getUlbId());
if(ulbname.equalsIgnoreCase("ADMIN")) {
logine = true;
return "allUlbs.xhtml?faces-redirect=true";
}
logine = true;
return "ReportsNew.xhtml?faces-redirect=true";
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getErrorTitle() {
return errorTitle;
}
public void setErrorTitle(String errorTitle) {
this.errorTitle = errorTitle;
}
public String getErrorDetails() {
return errorDetails;
}
public void setErrorDetails(String errorDetails) {
this.errorDetails = errorDetails;
}
public Boolean getLogine() {
return logine;
}
public void setLogine(Boolean logine) {
this.logine = logine;
}
public Integer getUlbId() {
return ulbId;
}
public void setUlbId(Integer ulbId) {
this.ulbId = ulbId;
}
public List<Ulb> getUlbs() {
return ulbs;
}
public void setUlbs(List<Ulb> ulbs) {
this.ulbs = ulbs;
}
public String getUlbName() {
return ulbName;
}
public void setUlbName(String ulbName) {
this.ulbName = ulbName;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}