1、编写一个简单页面,将登录的信息隐藏在一个DIV里面
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<af:document id="d1">
<af:form id="f1">
<af:resource type="javascript">
function addLoginInfo() {
document.getElementById("wsLogin").submit();
}
</af:resource>
</af:form>
<af:outputText value="页面正在跳转中..." id="ot1" inlineStyle="font-size:14px;"/>
<div style="display: none;">
<form id="wsLogin" method="post" action="${pageFlowScope.composerUrl}/j_security_check"
οnsubmit="return addLiginInfo()">
<input type="hidden" value="utf-8" name="j_character_encoding"/>
<table class="loginTable">
<tfoot>
<tr>
<td>
<button type="submit" class="Button"
id="loginButton">登 录</button>
</td>
</tr>
</tfoot>
<tr>
<th>用 户 名:</th>
<td>
<input type="text" id="username" name="j_username" class="input"
value="${pageFlowScope.username}"/>
</td>
</tr>
<tr>
<th>密 码:</th>
<td>
<input type="password" name="j_password" class="input" autocomplete="off"
value="${pageFlowScope.pwd}"/>
</td>
</tr>
</table>
</form>
</div>
</af:document>
</f:view>
</jsp:root>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<af:document id="d1">
<af:form id="f1">
<af:resource type="javascript">
function addLoginInfo() {
document.getElementById("wsLogin").submit();
}
</af:resource>
</af:form>
<af:outputText value="页面正在跳转中..." id="ot1" inlineStyle="font-size:14px;"/>
<div style="display: none;">
<form id="wsLogin" method="post" action="${pageFlowScope.composerUrl}/j_security_check"
οnsubmit="return addLiginInfo()">
<input type="hidden" value="utf-8" name="j_character_encoding"/>
<table class="loginTable">
<tfoot>
<tr>
<td>
<button type="submit" class="Button"
id="loginButton">登 录</button>
</td>
</tr>
</tfoot>
<tr>
<th>用 户 名:</th>
<td>
<input type="text" id="username" name="j_username" class="input"
value="${pageFlowScope.username}"/>
</td>
</tr>
<tr>
<th>密 码:</th>
<td>
<input type="password" name="j_password" class="input" autocomplete="off"
value="${pageFlowScope.pwd}"/>
</td>
</tr>
</table>
</form>
</div>
</af:document>
</f:view>
</jsp:root>
2、编写一个后台的backingBean类实现PagePhaseListener接口,将用户名密码取到后放入到作用域里,然后通过后台调用前台的JS代码来控制跳转。
import java.io.Serializable;
import javax.faces.context.FacesContext;
import oracle.adf.controller.v2.lifecycle.Lifecycle;
import oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
import oracle.adf.controller.v2.lifecycle.PagePhaseListener;
import oracle.adf.share.ADFContext;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;
public class MailRedirect extends CustomManagedBean implements Serializable, PagePhaseListener {
public MailRedirect() {
}
public void afterPhase(PagePhaseEvent pagePhaseEvent) {
}
public void beforePhase(PagePhaseEvent pagePhaseEvent) {
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_MODEL_ID) {
GetDBInfoBean bean = new GetDBInfoBean();
String currentUsername = ADFContext.getCurrent().getSecurityContext().getUserName();
MailInfoBean mail = (MailInfoBean)bean.getMailInfoByUserName(currentUsername).get(0);
String userName = mail.getMail();
String password = mail.getPassword();
this.setExpressionValue("#{pageFlowScope.uid}", userName);
this.setExpressionValue("#{pageFlowScope.pwd}", password);
FacesContext fctx = FacesContext.getCurrentInstance();
ExtendedRenderKitService erks = null;
erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
String script = "addLoginInfo();";
erks.addScript(fctx, script);
}
}
}
import javax.faces.context.FacesContext;
import oracle.adf.controller.v2.lifecycle.Lifecycle;
import oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
import oracle.adf.controller.v2.lifecycle.PagePhaseListener;
import oracle.adf.share.ADFContext;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;
public class MailRedirect extends CustomManagedBean implements Serializable, PagePhaseListener {
public MailRedirect() {
}
public void afterPhase(PagePhaseEvent pagePhaseEvent) {
}
public void beforePhase(PagePhaseEvent pagePhaseEvent) {
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_MODEL_ID) {
GetDBInfoBean bean = new GetDBInfoBean();
String currentUsername = ADFContext.getCurrent().getSecurityContext().getUserName();
MailInfoBean mail = (MailInfoBean)bean.getMailInfoByUserName(currentUsername).get(0);
String userName = mail.getMail();
String password = mail.getPassword();
this.setExpressionValue("#{pageFlowScope.uid}", userName);
this.setExpressionValue("#{pageFlowScope.pwd}", password);
FacesContext fctx = FacesContext.getCurrentInstance();
ExtendedRenderKitService erks = null;
erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
String script = "addLoginInfo();";
erks.addScript(fctx, script);
}
}
}