到 Google 资讯主页   
EasyJF首页   资料   源码   软件    论坛   网站    
   使用帮助    
    该信息为本站MyRSS系统缓存内容,部分图片及附件有可能无法正常使用.easyjf.comBEA dev2dev无关,不对该信息负责.通过http://kb.csdn.net/keyword/java//../../java/Articles/200606/c3af145a-8721-41ea-afd2-fcaf80550b32.html访问该信息的原始内容.
页面功能  【加入收藏】 【推荐给朋友】 【字体:  】 【关闭】   
深入Beehive标签库系列教程(1) - 基本NETUI标签
作者:肖菁 来源:BEA dev2dev  发布时间:2006-06-22 00:00:00.0

  浏览中向用户展示的内容主要分为文字、图片、超链接和表单等几大类,我们首先学习NETUI标签中用于显示文字、图片和超链接的标签,用于显示标单的标签将在后面的文章中一一介绍。

netui:span、netui:label、netui:content

  netui:span、netui:label、netui:content这三个标签都可以用于显示页面上的一段文字,也都支持使用value属性可以设置被显示文字的内容。

  netui:content标签仅仅支持defaultValue和value两个属性,其中的defaultValue属性用于指定该标签的默认内容。

  netui:span、netui:label提供的属性比netui:content多出很多。比如netui:span、netui:label支持设置css风格的style、styleClass属性,也支持适用于声明捕获鼠标事件的onClick、onMouseOver等属性。

   使用这三种标签显示“Hello World!”字符串的简单代码如下:

  1. <netui:span value=“Hello World!”/>
  2. <netui:label value=“Hello World!”/>
  3. <netui:content value=“Hello World!”/>

  我们可以为netui:span、netui:label设置更多的属性,比如使用netui:span标签显示“Hello World!”字符串、字符串颜色为红色、大小为18px的代码如下:

  1. <netui:label value=“Hello World!” style=“color:red;font-size:18px” />
  2. <netui:span value=“Hello World!” style=“color:red;font-size:18px” />

  netui:span和netui:content处理方式比较类似,只是在处理浏览器敏感的内容是有些差异,因为netui:span会将浏览器敏感的内容更新为符合要求的内容。

  比如”&amp;”对于浏览器而言是敏感内容,浏览器遇到”&amp;”时直接显示”&”。假设我们需要最终浏览器中最终显示的内容为”&amp;”,我们来看看使用这两个标签存在着什么不同之处。如果我们使用netui:span标签并且将他的value属性内容设置为”&amp;”,NETUI会自动输出”&amp;amp;”到浏览器,而浏览器会显示”&amp;”,这是我们想要的结果。如果我们使用netui:content标签并且同样将他的value属性内容设置为”&amp;”,NETUI会输出”&amp;”到浏览器,这种情况下浏览器只会显示”&”,这种情况下,我们需要将netui:content标签的value属性设置为”&amp;amp;”才能得到我们想要的结果。

  清单1中显示了netui:span、netui:label、netui:content标签更多的用法。

  清单1 web\textExamples.jsp

  1. <%@ page language="java"
  2. contentType="text/html;charset=gb2312"%>
  3. <%@ taglib
  4. uri="http://beehive.apache.org/netui/tags-databinding-1.0"
  5. prefix="netui-data"%>
  6. <%@ taglib uri="http://beehive.apache.org/netui/tags-html-1.0"
  7. prefix="netui"%>
  8. <%@ taglib
  9. uri="http://beehive.apache.org/netui/tags-template-1.0"
  10. prefix="netui-template"%>
  11. <netui:html>
  12. <head>
  13. <title>Text Examples</title>
  14. <netui:base/>
  15. </head>
  16. <netui:body>
  17. <center>使用标签输出文字的例子</center><BR>
  18. 使用netui:span输出文字:<br>
  19. &nbsp;&nbsp;&nbsp;&nbsp;
  20. <netui:span value="Hello World!"/><BR>
  21. 使用netui:span输出&amp;amp;:<br>
  22. &nbsp;&nbsp;&nbsp;&nbsp;
  23. <netui:span value="&amp;"/><BR>
  24. 使用netui:span + css输出文字:<BR>
  25. &nbsp;&nbsp;&nbsp;&nbsp;
  26. <netui:span value="Hello World!"
  27. style="color:red;font-size:18px" /><BR>
  28. <BR>
  29. <BR>
  30. 使用netui:label输出文字:<BR>
  31. &nbsp;&nbsp;&nbsp;&nbsp;
  32. <netui:label value="Hello World!"/><BR>
  33. 使用netui:label输出&amp;amp;:<br>
  34. &nbsp;&nbsp;&nbsp;&nbsp;
  35. <netui:label value="&amp;"/><BR>
  36. 使用netui:label + css输出文字:<BR>
  37. &nbsp;&nbsp;&nbsp;&nbsp;
  38. <netui:label value="Hello World!"
  39. style="color:red;font-size:18px" /><BR>
  40. <BR>
  41. <BR>
  42. 使用netui:content输出文字:<BR>
  43. &nbsp;&nbsp;&nbsp;&nbsp;
  44. <netui:content value="Hello World!"/><BR>
  45. 使用netui:content输出&amp;amp;:<br>
  46. &nbsp;&nbsp;&nbsp;&nbsp;
  47. <netui:content value="&amp;amp;"/><BR>
  48. </netui:body>
  49. </netui:html>

netui:iamge、netui:imageAnchor、netui:imageButton

  页面上的图片通常有三种用途:一种用于简单的显示图片,一种是作为超链接的图片,还有一种是用于Form中的提交按钮的图片按钮。netui标签库中用netui:iamge、netui:imageAnchor、netui:imageButton标签来对应显示不同功能的图片。

  netui:image标签用于在页面上显示一张图片,src属性用于设置被显示图片的路径。下面的代码可用于在页面上显示名为examples.gif的gif图片。

  <netui:image src=“images/examples.gif”/>

  netui:imageAnchor用于显示带有超链接的图片,它继承了netui:anchor的全部属性,只是超链接的载体由文件变成了图片,和netui:anchor一样,我们需要根据链接目标的不同选择action、href、linkName来设置目标地址,我们可以使用下面的代码来完成显示超链接到www.bea.com网站的examples.gif图片,其他形式下的属性设置方式请参考netui:anchor标签中的说明。

  <netui:imageAnchor src=“images/bea.gif” href=“www.bea.com.cn” border=“0” />

  netui:imageButton标签用于在页面上显示Form中用于提交的图片按钮,我们可以用下面的代码来显示一个可用于提交的图片按钮,用于显示的图片是examples.gif。

  1. <netui:form action=“begin”>
  2. 请输入用户名:<BR>
  3. <netui:inputText dataSource=”userName” />
  4. <BR>
  5. <netui:imageButton src=”images/submit.gif” />
  6. </netui:form>

  图片标签例子的全部内容请参考清单2。

  清单2 web\imageExamples.jsp

  1. <%@ page language="java"
  2. contentType="text/html;charset=gb2312"%>
  3. <%@ taglib
  4. uri="http://beehive.apache.org/netui/tags-databinding-1.0"
  5. prefix="netui-data"%>
  6. <%@ taglib uri="http://beehive.apache.org/netui/tags-html-1.0"
  7. prefix="netui"%>
  8. <%@ taglib
  9. uri="http://beehive.apache.org/netui/tags-template-1.0"
  10. prefix="netui-template"%>
  11. <netui:html>
  12. <head>
  13. <title>Image Examples</title>
  14. <netui:base/>
  15. </head>
  16. <netui:body>
  17. <center>使用标签显示图片的例子</center><BR><BR>
  18. 使用netui:image显示图片:<BR>
  19. <netui:image src="images/examples.gif"/><BR>
  20. <BR>
  21. <BR>
  22. 使用netui:imageAnchor显示带超链接的图片<BR>
  23. 使用netui:imageAnchor显示带超链接的图片,
  24. 链接到aciton:<BR>
  25. <netui:imageAnchor src="images/bea.gif"
  26. action="begin" border="0" /><BR>
  27. <BR>
  28. 使用netui:imageAnchor 的 href 属性,
  29. 链接到本地JSP内容:<BR>
  30. <netui:imageAnchor src="images/bea.gif"
  31. href="/index.jsp" border="0" /><BR>
  32. <BR>
  33. 使用netui:imageAnchor 的 href 属性,
  34. 链接到远程JSP内容:<BR>
  35. <netui:imageAnchor src="images/bea.gif"
  36. href="http://www.bea.com.cn" border="0" /><BR>
  37. <BR>
  38. 使用netui:imageAnchor 的 linkName 属性,
  39. 链接到命名锚点:<BR>
  40. <netui:imageAnchor src="images/bea.gif"
  41. linkName="linka" border="0" /><BR>
  42. <BR>
  43. 使用netui:imageAnchor 显示超链接,同时绑定参数<BR>
  44. <netui:imageAnchor src="images/bea.gif"
  45. href="http://www.bea.com.cn" border="0">
  46. <netui:parameter name="username" value="user"/>
  47. <netui:parameter name="password" value="pass"/>
  48. </netui:imageAnchor><BR>
  49. <BR>
  50. <BR>
  51. 使用netui:imageButton 显示用于提交的图片式按钮
  52. <BR><BR>
  53. <netui:form action="begin">
  54. 请输入用户名:<br>
  55. <netui:textBox dataSource=" userName" />
  56. <BR>
  57. <netui:imageButton src="images/submit.gif" />
  58. </netui:form>
  59.  
  60. <a name="linka"/>
  61. 此处是命名锚点
  62. </netui:body>
  63. </netui:html>

netui:anchor

  netui:anchor标签用于在页面中显示超链接内容,超链接可以是一个简单的超级链接,也可以用于完成表单(Form)提交和调用JavaScript的函数完成其他工作。netui:anchor标签支持的主要属性如下:

  1. value
  2.   超链接的显示文字。

  3. action
  4.   如果超链接的目标是页面流的一个Action,必须使用这个属性来设置netui:anchor链接的目标地址。比如我们要链接到页面流中的begin这个Action,应该使用下面的代码来设置netui:anchor标签。

      <netui:anchor action=“begin” value=“link to begin action”/>

  5. href
  6.   超链接的目标地址。如果是链接到本域中的jsp页面或者其他静态页面,可以直接使用相对地址设置href属性;如果目标地址是其他域中的内容,那么href的地址必须使用“http:// ”字符串开头。

      比如我们可以使用下面的代码链接到相对目录为jsp/test.jsp文件:

      <netui:anchor href=“jsp/test.jsp” value=“link to jsp/test.jsp”/>

      如果我们的目标地址是BEA的中国区网站www.bea.com.cn,因为它和我们的应用不再同一个域中,所以我们只能使用下面的代码来显示这个超链接:

      <netui:anchor href=“http://www.bea.com” value=“BEA中文网站”/>

  7. linkName
  8.   如果超链接的目标是本文件中的一个命名锚点(在html中我们可以使用<a name=“dest” />这样的标记来加入一个命名锚点),我们必须使用linkName属性设置anchor标签。比如我们的超链接指向一个名为dest的命名锚记,我们的netui:anchor标签应该使用下面的代码来实现:

      <netui:anchor linkName=“dest” value=“link to anchor dest”/>

  9. formSubmit

  如果我们希望使用一个超级链接来完成表单的提交,我们只需要将anchor标签放置在netui:form标签中,然后设置它的formSubmit属性设置为”true”就可以了,我们可以用下面的代码来实现通过点击提交链接来完成表单的提交:

  1. <netui:form action=“begin”>
  2. 用户名:
  3. <netui:textBox dataSource=“username”/>
  4. 密码:
  5. <netui:textBox password=“true”
  6. dataSource=“actionForm.password”/>
  7. <netui:anchor formSubmit=“true”>提交</netui:anchor>
  8. </netui:form>

  除了简单的显示超链接外,我们通常还需要为超链接提供一些参数,比如我们需要显示的一个超链接的目标地址是http://www.bea.com.cn?username=user&password=pass,这种情况下我们需要用另外一个netui标签netui: parameter来协助netui:anchor完成工作,netui: parameter标签的name属性提供参数名称,value属性提供参数的内容。上面的这个链接我们可以使用下面的代码来完成。

  1. <netui:anchor href=“http://www.bea.com.cn”
  2. value=“BEA中文网站”>
  3. <netui:parameter name=“username” value=“user”/>
  4. <netui:parameter name=“password” value=“pass”/>
  5. </netui:anchor>

  netui:anchor标签的例子全部内容请参考清单3。

  清单3 web\anchorExamples.jsp

  1. <%@ page language="java"
  2. contentType="text/html;charset=gb2312"%>
  3. <%@ taglib
  4. uri="http://beehive.apache.org/netui/tags-databinding-1.0"
  5. prefix="netui-data"%>
  6. <%@ taglib uri="http://beehive.apache.org/netui/tags-html-1.0"
  7. prefix="netui"%>
  8. <%@ taglib
  9. uri="http://beehive.apache.org/netui/tags-template-1.0"
  10. prefix="netui-template"%>
  11. <netui:html>
  12. <head>
  13. <title>Anchor Examples</title>
  14. <netui:base/>
  15. </head>
  16. <netui:body>
  17. <center>使用标签输出文字的例子</center><BR>
  18. 使用netui:anchor 的 href 属性,链接到aciton:<BR>
  19. <netui:anchor action="begin" value="-> 开始页" /><BR>
  20. <BR>
  21. 使用netui:anchor 的 href 属性,链接到本地JSP:<BR>
  22. <netui:anchor href="/index.jsp" value="-> 开始页" /><BR>
  23. <BR>
  24. 使用netui:anchor 的href属性,链接到外部Web内容:<BR>
  25. <netui:anchor href=http://www.bea.com.cn
  26. value="-> BEA中文网站" /><BR>
  27. <BR>
  28. 使用netui:anchor 的 linkName 属性,链接到命名锚点:
  29. <BR>
  30. <netui:anchor linkName="linka" value="-> 命名锚点" />
  31. <BR>
  32. 使用netui:anchor 显示提交按钮:<BR>
  33. <netui:form action="begin">
  34. 用户名:
  35. <netui:textBox dataSource="username" />
  36. <BR>
  37. 密码:
  38. <netui:textBox password="true"
  39. dataSource="password" /><BR>
  40. <netui:anchor formSubmit="true">提交</netui:anchor>
  41. </netui:form>
  42.  
  43. 使用netui:anchor显示超链接,同时绑定参数<BR>
  44. <netui:anchor href=http://www.bea.com.cn
  45. value="-> BEA中文网站">
  46. <netui:parameter name="username" value="user"/>
  47. <netui:parameter name="password" value="pass"/>
  48. </netui:anchor><BR>
  49. <BR>
  50. <BR>
  51.  
  52. <a name="linka"/>
  53. 此处是命名锚点
  54. </netui:body>
  55. </netui:html>

 
相关文章
 
页面功能  【加入收藏】 【推荐给朋友】 【字体:  】 【关闭】   


EasyJF.com 2006 隐私政策 使用EasyJF前必读