easyjweb实战代码片断
在eclipse中,加入一个单例的热键
取名为singleton,加入到模板中,就可以用singleton来快速生成这个代码片断了。
private static ${primary_type_name} instance;
private final static Object keyFor${primary_type_name} = new Object();
public static ${primary_type_name} getInstance() {
if (${primary_type_name}.instance == null) {
synchronized (${primary_type_name}.keyFor${primary_type_name}) {
if (${primary_type_name}.instance == null) {
${primary_type_name}.instance = new ${primary_type_name}();
}
}
}
return ${primary_type_name}.instance;
}
private ${primary_type_name}() {
}
${cursor}
加入一个生成log的热键
取名为log,加入到模板中,就可以用log来快速生成这个代码片断了。
private static final Log log = LogFactory.getLog(${primary_type_name}.class.getName());
如果一个类型为boolean的属性,在页面上我不想要看到为一个输入框,而是以radio的形式展现给用户,
为了表现上的完美,当点击这个radio上面的提示文字的时候也可以选中这个选项,html里有一个label 加上for这个radio 的ID就可以实现这一小小需求了。
当从客户端访问的时候还要检查上次的结果是哪一个选项被选中,则使用#if(!$friendLinkApplication )checked="true"#end代码段即可实现了。
<input type="radio" name="friendLinkApplication" value="false" id="friendLinkApplication_one" #if(!$friendLinkApplication )checked="true"#end/>
<label for="friendLinkApplication_one">不需要</label>
<span style="margin-left:80px"/>
<input type="radio" name="friendLinkApplication" value="true" id="friendLinkApplication_two" #if($friendLinkApplication )checked="true"#end/>
<label for="friendLinkApplication_two">需要</label>
这个forward可以自动识别动态和静态地址,如果页面是以动态地址访问的,则给出的地址为portal/index.html,如果是以动态地址访问,
则给出了portal.ejf?cmd=index的地址
$html.forward("portal.index") portal/index.html
这样会生成一个带分页的URL,如果当前为1页并且为静态地址,则为portal/index/1.html,如果为动态地址则为portal.ejf?cmd=index&currentPage=1
$html.autoLink('[portal.index/.]') portal/index/1.html
同上
$html.autoLink('[portal.index/sn=yy/.]') portal/index/yy/1.html
如果应用在/的WEB上下文中运行且浏览器语言为中文,则给出<a href='/portal.ejf?cmd=index'>首页</a>
的代码段给用户浏览器。
<a href='$html.url("portal.ejf?cmd=index")'>$lang.get("global.index")</a>
当mouseover到要删除按钮时在指定的区域给出指定语言的提示。
onmouseover="return COMMON.$('application.descriptions').innerHTML='$!lang.get("application.delete.tips")';" onmouseout="return COMMON.$('application.descriptions').innerHTML=' ';return false;"
一个分页的示例代码
#set ($u = $!NU.snq.dir("announce").pageSize("$!pageSize"))
$NU.pageForm("/portal.ejf?cmd=announce")
#foreach($info in $!u.page($!currentPage).list)
·<a class="news" href="$html.autoLink($info)" rel="external" title="$!info.title">$!NU.format($info.title,25,false)</a><br />
#end
在页面上显示分页段
<div id="pagination">
$html.pagination($!u.pageList.currentPage.toString(),$!u.pageList.pages.toString(),"[portal.announce]")
</div>
同上
$html.pagination($!currentPage.toString(),$!pages.toString(),"[portal.announce]")
另一种分页展示
<div id="pagination">
<ul><li class="info">第<strong>$!currentPage</strong>/<strong>$!u.pageList.pages</strong>页 每页<strong>$!u.pageList.pageSize</strong>条记录 [共<b>$!u.pageList.rowCount</b>条记录]
分页:$NU.pageation($!u.pageList.currentPage.toString(),$!u.pageList.pages.toString(),"[portal.announce]")</li>
</ul>
</div>
列出index栏目下的所有一级子栏目
#foreach($dir in $!NU.dir("index").children)
<tr>
<td>$dir.title</td>
</tr>
#end
得到一个三个一行列表
#foreach($subList in $CommUtil.toRowChildList($NU.dir("index").children,3))
<tr>
#foreach($info in $subList)
<td>
$!info.title
</td>
#end
</tr>
#end
得到所有index下面的文章按指定的条件
#foreach($info in $!NU.snq.dir("index").orderBy("displayTime").number(7).desc().titleSize(11).list)
<tr>
<td height="24" align="left">
·<a href="$html.autoLink($info)" target="_blank" title="$info.title" class="news" rel="external">$!info.title $!CommUtil.format($!{info.displayTime})</a>
</td>
</tr>
#end