用户控件 UserControl
在 hoyi web里面,用户控件UserControl和MasterPage,ContentPage都是使用Hoyipage来实现的。
topNavCtrls.java
package WebRoot.usctrls;
import org.hoyi.dishop.Hoyipage;
import org.hoyi.wb.comment.RequestMode;
import org.hoyi.wb.comment.RequestType;
import modules.userexpert;
import util.SessionUtil;
/**
* 导航栏
* @author SAM
*
*/
@RequestMode(MODE={ RequestType.POST})
public class topNavCtrls extends Hoyipage{
public topNavCtrls(String id, Hoyipage _parent){
super(id, _parent);
}
public String GetRootURL()
{
if (parent!= null) {
return parent.GetRootURL();
}
return super.GetRootURL();
}
public String GetLoginedName()
{
return userexpert.GetLoginedName(getRequest());
}
public String GetLoginedButtons()
{
return userexpert.GetLoginedButtons(getRequest(), this.parent.getClass());
}
public String GetLogined()
{
return String.valueOf(SessionUtil.IsLogined(getRequest()));
}
@RequestMode(MODE={ RequestType.POST})
public void TestUserControl()
{
this.WriteUTF8JSONDATA("AAA");
}
@RequestMode(MODE={ RequestType.POST})
public void LogOut() {
SessionUtil.LogOut(getRequest());
this.WriteUTF8JSONDATA("Success Logout");
}
}
<script type="text/javascript">
$(function(){
$('#btnLogOut').click(function(){
var pdata = {"behavior":"LogOut"};
HOYI_POST(pdata, function(rdata, status){
if(rdata.status == 1){
window.location.href = window.location.href;
}else{
alert("登录失败");
}
});
});
});
</script>
<nav id="navs" class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<img src="<%# GetRootURL() #%>img/headpage/logo.png" />
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav" style="margin-left:24%;">
<li><a href="<%# GetRootURL() #%>index.hoyip">首页</a></li>
<li><a href="<%# GetRootURL() #%>view/x/view.hoyip"></a></li>
<%# GetLoginedButtons() #%>
</ul>
</div>
</div>
</nav>
母版页 uscentermaster.hoyip.html
母版页可以使用UserControl和ContentPage,
ContentPage为内容页。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="UTF-8">
<%# getMeta() #%>
<title><%# getPagetitle() #%></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<script src="<%# GetRootURL() #%>js/jquery-2.1.3/jquery-2.1.3.js"></script>
<link href="<%# GetRootURL() #%>js/bootstrap-3.3.5-dist/css/bootstrap-theme.min.css" rel="stylesheet" />
<link href="<%# GetRootURL() #%>js/bootstrap-3.3.5-dist/css/bootstrap.min.css" rel="stylesheet" />
<script src="<%# GetRootURL() #%>js/bootstrap-3.3.5-dist/js/bootstrap.min.js"></script>
<link href="<%# GetRootURL() #%>css/bootstrap-change.css" rel="stylesheet" />
<link href="<%# GetRootURL() #%>css/view.css" rel="stylesheet" />
<script src="<%# GetRootURL() #%>js/hoyi-req.js"></script>
<script type="text/javascript">
$(function(){
$('#btnLogOut').click(function(){
var pdata = {"behavior":"LogOut"};
HOYI_POST(pdata, function(rdata, status){
if(rdata.status == 1){
window.location.href = window.location.href;
}else{
alert("登录失败");
}
});
});
});
</script>
</head>
<body>
<hoyip:UserControl Id="topnavs" />
<hoyip:UserControl Id="topbaonavi" />
<div class="container" style="min-height:740px;">
<div class="row">
<div class="col-xs-2">
<hoyip:UserControl Id="leftnavi" />
</div>
<div class="col-xs-10">
<hoyip:ContentPage Id="contentDemo" />
</div>
</div>
</div>
<hoyip:UserControl Id="top" />
</body>
</html>
package WebRoot.masterpage;
import org.hoyi.dishop.Hoyipage;
import org.hoyi.util.DomainUtil;
import org.hoyi.wb.comment.RequestMode;
import org.hoyi.wb.comment.RequestType;
import WebRoot.usctrls.leftnavi;
import WebRoot.usctrls.topNavCtrls;
import WebRoot.usctrls.topbaonavi;
import modules.userexpert;
import util.SessionUtil;
public class uscenterMaster extends Hoyipage {
topNavCtrls reptopnav = new topNavCtrls("topnavs", this);
topbaonavi topbaonavi = new topbaonavi("topbaonavi", this);
leftnavi leftnavi = new leftnavi("leftnavi", this);
public void SetLEFT(String _leftnavi)
{
leftnavi.LEFTNAVITYPE =_leftnavi;
}
private String pagetitle="UsCenter MasterPage";
private String meta = "<meta key=\"\" />";
public String getMeta() {
return meta;
}
public void setMeta(String meta) {
this.meta = meta;
}
public String getPagetitle() {
return pagetitle;
}
public void setPagetitle(String pagetitle) {
this.pagetitle = pagetitle;
}
public String GetLoginedName()
{
return userexpert.GetLoginedName(getRequest());
}
public String GetLoginedButtons()
{
return userexpert.GetLoginedButtons(getRequest(), this.parent.getClass());
}
public String GetLogined()
{
return String.valueOf(SessionUtil.IsLogined(getRequest()));
}
@RequestMode(MODE={ RequestType.POST})
public void LogOut() {
SessionUtil.LogOut(getRequest());
this.WriteUTF8JSONDATA("Success Logout");
}
private String rooturl = DomainUtil.GetRootURL(this.getClass());
public String GetRootURL(){
return rooturl;
}
public void setRooturl(String rooturl) {
this.rooturl = rooturl;
}
public void setNavInfo(String navurl, String navname) {
this.topbaonavi.setNavurl(navurl);
this.topbaonavi.setNavname(navname);
}
}
pwdchange.hoyip.html
<div class="panel panel-default">
<div class="row">
<div class="input-group" style="margin-top: 20px; line-height: initial; width: 50%; margin-left: 5%; margin-top: 20px; font-weight: bold;"> 修改密码</div>
</div>
<div class="row">
<input type="text" class="form-control" id="exampleInputName2" placeholder="请输入原密码" style="width: 50%; margin-left: 5%; margin-top: 20px;">
</div>
<div class="row">
<input type="password" class="form-control" id="exampleInputName2" placeholder="请输入新密码" style="width: 50%; margin-left: 5%; margin-top: 20px;">
</div>
<div class="row">
<input type="password" class="form-control" id="exampleInputName2" placeholder="再次输入密码" style="width: 50%; margin-left: 5%; margin-top: 20px;">
</div>
<div class="row">
<button type="button" class="btn btn-success" style="margin-left: 5%; margin-top: 20px; width: 50%;">修改密码</button>
</div>
<div class="row" style="height: 100px;"></div>
</div>
pwdchange.java
package WebRoot.uscenter;
import java.io.IOException;
import org.hoyi.dishop.Hoyipage;
import WebRoot.masterpage.uscenterMaster;
public class pwdchange extends Hoyipage {
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>uscenterMaster master = new uscenterMaster();
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>public void OnPreInit() throws IOException {
<span style="white-space:pre"> </span>// TODO Auto-generated method stub
<span style="white-space:pre"> </span>this.SetMasterPage(master, "master");
<span style="white-space:pre"> </span>master.SetLEFT("PWDCHANGE");
<span style="white-space:pre"> </span>master.setPagetitle(" - 修改密码");
<span style="white-space:pre"> </span>master.setNavInfo("uscenter/pwdchange.hoyip", "修改密码");
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>super.OnPreInit();
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>
}