我需要检查以下情况,
if (request.getParameter("onumber") != null && request.getParameter("onumber") != "" && request.getParameter("ocode") != null && request.getParameter("ocode") != "") {
如果是,我需要自动调用StatusBean的submit()方法。
我尝试了下面而没有测试onumber和ocode条件,但它没有工作。我错过了什么吗?
<script type="text/javascript">
function test() {
alert("Called test"); //This is not even called
document.getElementById('LoginForm:submitButton1').click();
}
</script>
<body onload="test();">
<f:view>
<h:form id="LoginForm" onsubmit="return validateLoginForm();">
<h:commandButton style="display:none" action="#{StatusBean.submit}" id="submitButton1"/>
...
...
</h:form>
</f:view>
</body>
另请告诉我如何使用onumber和ocode条件进行测试。 感谢。
答案 0 :(得分:1)
抱歉,上面的代码不起作用,但此代码可以。它与你的几乎完全相同。不知道为什么你的不是。
<!DOCTYPE html>
<html xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<link rel="stylesheet" type="text/css" href="themes/local/tinstyle.css"/>
</h:head>
<script type="text/javascript">
function doSubmit() {
document.getElementById('mmTestForm:delBtn').click();
}
</script>
<h:body onload="doSubmit()">
<h:form id="mmTestForm" action="#{mmTestBean.delete}">
<p:commandButton id="delBtn" value="" action="#{mmTestBean.delete}" ajax="false" />
</h:form>
</h:body>
</html>
package gov.irs.eservices.tin.mbeans;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="mmTestBean")
@SessionScoped
public class MMTestBean {
public String delete() {
System.out.println("here");
return "mainmenu";
}
}
答案 1 :(得分:0)
您可以获取查询参数并将它们存储在辅助bean中,并且只有当这两个按钮都按这样传递时才启用该按钮:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:metadata>
<f:viewParam name="onumber" value="#{userBean.onumber}"/>
<f:viewParam name="ocode" value="#{userBean.ocode}"/>
</f:metadata>
<h:head>
<title>Welcome</title>
</h:head>
<h:body>
<h:form prependId="false">
<h:commandButton value="Submit" disabled="#{ empty userBean.onumber or empty userBean.ocode}" />
</h:form>
</h:body>
并为辅助bean中的参数创建setter / getter:
public class UserBean implements Serializable {
private static final long serialVersionUID = 1L;
private String ocode;
private String onumber;
public String getOcode() {
return ocode;
}
public void setOcode(String ocode) {
this.ocode = ocode;
}
public String getOnumber() {
return onumber;
}
public void setOnumber(String onumber) {
this.onumber = onumber;
}
}