Appfuse:添加自訂頁面組件

來源:互聯網
上載者:User

標籤:

我之前是做ASP.NET的,碰到被多個頁面都使用的類似組件後,就想著採用ascx(使用者自訂群組件)來解決,那做Java我也想用這種方案。

我要做的效果如下:

實現方案:tag方式(自訂標籤)

1. 首先定義自己的tag

 1 <%@ tag body-content="scriptless" pageEncoding="UTF-8"%> 2 <%@ attribute name="table" required="true"%> 3 <%@ attribute name="idfield" required="true"%> 4 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> 5 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 6 <c:set var="base" value="${pageContext.request.contextPath}" /> 7 <c:set var="typeList" /> 8 <script src="<c:url value="/scripts/jquery/jquery.1.10.2.min.js" />"></script> 9 <form method="post">10     <div id="divRecomment">11         <fmt:message key="recomment.title" />12         &nbsp;&nbsp;13         <select id="recommendAction" name="recommendAction">14             <c:forEach items="${recommenttype}" var="t">15                 <option value="${t.key}">${t.value}</option>16             </c:forEach>17         <select>18         &nbsp;&nbsp; <input type="button" onclick="handleRecomment();"19             value=‘<fmt:message key="recomment.submit"/>‘ class="btn btn-primary" />20     </div>21 </form>
recommend.tag

2. 使用自訂的標籤

<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>

<t:recommend table="" idfield=""></t:recommend>

3. recommenttype 的資料來源:使用頁面對應的Controller中的handleRequest

1 HashMap<String,String> recommentType = new HashMap<String,String>();2         recommentType.put("1", "首頁");  3         recommentType.put("2", "其他");   4         request.setAttribute(Constants.RECOMMENT_TYPE, recommentType);
handleRequest

附用到的樣式

1 #divRecomment{2     margin-left:12px;3 }4 #divRecomment select{5     width:200px;6     height:38px;7     border:1px solid #cccccc;8 }
main.css

 

Appfuse:添加自訂頁面組件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.