论坛首页 Java企业应用论坛

tapestry5中select的用法

浏览 11361 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-02-28  
java 代码
 
  1. // Copyright 2007 The Apache Software Foundation  
  2. //  
  3. // Licensed under the Apache License, Version 2.0 (the "License");  
  4. // you may not use this file except in compliance with the License.  
  5. // You may obtain a copy of the License at  
  6. //  
  7. //     http://www.apache.org/licenses/LICENSE-2.0  
  8. //  
  9. // Unless required by applicable law or agreed to in writing, software  
  10. // distributed under the License is distributed on an "AS IS" BASIS,  
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  12. // See the License for the specific language governing permissions and  
  13. // limitations under the License.  
  14.   
  15. package org.qiwen.pages;  
  16.   
  17. import java.util.Map;  
  18.   
  19. import org.apache.tapestry.Block;  
  20. import org.apache.tapestry.annotations.Inject;  
  21. import org.apache.tapestry.annotations.Persist;  
  22. import org.apache.tapestry.annotations.Retain;  
  23. import org.apache.tapestry.ioc.internal.util.CollectionFactory;  
  24.   
  25. public class BlockDemo  
  26. {  
  27.     @Inject  
  28.     private Block _fred;  
  29.   
  30.     @Inject  
  31.     private Block _barney;  
  32.   
  33.     // Blocks not injected until page load, so must lazily initialize the map.  
  34.     @Retain  
  35.     private Map<String, Block> _blocks = null;  
  36.   
  37.     @Persist  
  38.     private String _blockName;  
  39.   
  40.     public Block getBlockToRender()  
  41.     {  
  42.         if (_blocks == null)  
  43.         {  
  44.             _blocks = CollectionFactory.newMap();  
  45.             _blocks.put("fred", _fred);  
  46.             _blocks.put("barney", _barney);  
  47.         }  
  48.   
  49.         return _blocks.get(_blockName);  
  50.     }  
  51.   
  52.     public String getBlockName()  
  53.     {  
  54.         return _blockName;  
  55.     }  
  56.   
  57.     public void setBlockName(String blockName)  
  58.     {  
  59.         _blockName = blockName;  
  60.     }  
  61.   
  62. }  


Html 代码
 
  1. <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">   
  2.       
  3.     <form t:type="Form">  
  4.         <select t:type="Select" t:id="blockName" model="',fred,barney'" onchange="this.form.submit();"/>   
  5.         <label t:type="Label" for="blockName">Block to display</label>  
  6.     </form>  
  7.       
  8.     <p>The block: ${blockToRender}</p>  
  9.           
  10. </html>  
   发表时间:2007-02-28  
老兄紧跟时代潮流啊,Tapestry5好。
0 请登录后投票
   发表时间:2007-02-28  
我是女的好不好
0 请登录后投票
   发表时间:2007-02-28  
还要在html模板中加上如下语句:
<t:block id="fred">Block fred.</t:block>
<t:block id="barney">Block barney.</t:block>

这个程序才能正常运行。
0 请登录后投票
   发表时间:2007-03-13  
美女,如何动态的控制select中的内容呀???????????
0 请登录后投票
   发表时间:2007-04-01  
	public SelectModel getFromModel() {

		List<OptionModel> options = new ArrayList<OptionModel>();
		OptionModel blank = new OptionModelImpl("", false, "");
		OptionModel beiJing = new OptionModelImpl("BeiJing", false, "1");
		OptionModel shangHai = new OptionModelImpl("ShangHai", false, "2");
		OptionModel tianJin = new OptionModelImpl("TianJin", false, "3");
		options.add(blank);
		options.add(beiJing);
		options.add(shangHai);
		options.add(tianJin);
		return new SelectModelImpl(null, options);
	}


    <select t:type="select" model="fromModel" value="user.from"/>


不过搞不清楚为什么值只能是String类型而不能是Integer类型。
默认的encoder是org.apache.tapestry.ValueEncoder
不会对于Integer类型的value需要自己写一个ValueEncoder吧。
0 请登录后投票
   发表时间:2007-04-01  
在http://tapestry.apache.org/tapestry5/tapestry-core/component-parameters.html位置没有找到radio组件(单选框)

只有如下组件,为什么?
AbstractField
AbstractTextField
ActionLink
Any
BeanEditForm
Checkbox
Delegate
Errors
Form
Grid
GridCell
GridColumns
GridPager
GridRows
If
Img
Label
Loop
Output
OutputRaw
PageLink
PasswordField
RenderObject
Select
Submit
TextArea
TextField
0 请登录后投票
   发表时间:2007-04-02  
Model的实现类是可以自己实现的。
0 请登录后投票
   发表时间:2007-04-02  
引用
Model的实现类是可以自己实现的。



是可以自己实现,不过tapestry对这个基本的组件总该有个实现吧,有些奇怪。
0 请登录后投票
   发表时间:2007-04-02  
jamesby 写道
引用
Model的实现类是可以自己实现的。



是可以自己实现,不过tapestry对这个基本的组件总该有个实现吧,有些奇怪。


当然有。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics