- 浏览: 148004 次
- 性别:
- 来自: 苏州
文章分类
- 全部博客 (87)
- seam/jsf (22)
- java (24)
- spring (6)
- hibernate (2)
- Mysql (4)
- web (1)
- JMS (0)
- 计算机(computer) (1)
- linux (3)
- eclipse (4)
- Javascript (1)
- xstream (3)
- JPA (2)
- 汇编 (1)
- HttpClient (1)
- quartz (1)
- J2EE (2)
- EJB (1)
- restful web (1)
- maven (1)
- TTServer (3)
- restlet (0)
- jquery (0)
- Firebug (0)
- jquery Masonry+Infinite-Scroll (0)
- JACOB (0)
- elasticsearch (0)
最新评论
-
tuspark:
关于ApplicationContextAware的详细介绍, ...
ApplicationContextAware -
hc_face:
应该是 环境被初始化的时候,bean 也一并被初始化吧。先后顺 ...
ApplicationContextAware -
奇林醉:
有点明白了
Collections.unmodifiableList() -
tcking:
HashSet不关心迭代的次序,也就是说下一次的迭代次序可能就 ...
HashSet LinkedHashSet TreeSet -
yzhw:
我要去试试
seam前端提速
Forum: Seam Users Forum ListTopic List
Solution for ui:repeat with varStatus and new parameters "from" and "to" 07. Aug 2009, 08:25 America/New_York | Link
Dieter Rehbein
Since I needed a varStatus for ui:repeat, I've create my own version of the ui:repeat tag, which has the following new features:
It now supports the attribute “varStatus”. The status object has the following attributes:
■index: the current - zero based - index
■count: the number of iterations. If the count is not available (e.g. for variables of type ResultSet): -1
■last: true, if the current iteration is the last one
■first: true, if the current iteration is the first one
■from, to: for simple for-loops without a collection
example 1:
<ui:repeat value="#{myCollection}" var="item" varStatus="status">
<h:outputText value="...." rendered="#{status.first}"/>
<h:outputText value="...." rendered="#{status.index gt 5}"/>
.......
</ui:repeat>
example 2:
<ui:repeat var="i" varStatus="status" from="5" to="7">
value: #{i}<br/>
index: #{status.index}<br/>
</ui:repeat>
The second example renders the following output:
value: 5
index: 0
value: 6
index: 1
value: 7
index: 2The sourcecode for the new version of the class UIRepeat can be downloaded from here (unfortunately this forum does not support file uploads).
To use it, you have to add a new entry to the file WEB-INF/faces-config.xml:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="1.2"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<!-- this component entry is new: -->
<component>
<component-type>facelets.ui.Repeat</component-type>
<component-class>com.alturos.gui.facelets.UIRepeat</component-class>
</component>
<application>
<locale-config>
<default-locale>de</default-locale>
<supported-locale>cs</supported-locale>
<supported-locale>de</supported-locale>
<supported-locale>en</supported-locale>
<supported-locale>fr</supported-locale>
<supported-locale>it</supported-locale>
<supported-locale>ru</supported-locale>
</locale-config>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
</faces-config>
Tags: facelets
12 Replies:
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 07. Aug 2009, 08:27 America/New_York | Link
Dieter Rehbein
sorry, there are some mistakes in the previous post:
the status object provides the following attributes:
■index
■count
■last
■first
The tag has the following new attributes:
■from
■to
The attribute varStatus already existed but it was not used by the original UIRepeat version.
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 23. Nov 2009, 22:12 America/New_York | Link
Kirill Kudriavtsev
hi, thanks for this solution
but in your class exist a little mistake (i found at least one) your code
private synchronized DataModel getDataModel()
{
if(this.model == null)
{
...
}
status = new Status(model.getRowCount());
return this.model;
}
should be
private synchronized DataModel getDataModel()
{
if(this.model == null)
{
...
status = new Status(model.getRowCount());
}
return this.model;
}
otherwise varStatus.index doesn't work
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 26. Jan 2010, 16:55 America/New_York | Link
Dmitri Ilyin
Hi,
i would also need a varStatus attribute.
Dieter, i've tried your solution and could not get it work. The status.index stays empty.
have you already used your Tag in you projects? May be you have already a fixed vertion. Or a tip how to get it work.
The Tag would be very usefull.
thanks a lot regards
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 04. Feb 2010, 15:34 America/New_York | Link
Emanuel Palacio
Worked fine for me. Thanks a lot Dieter!
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 06. Feb 2010, 17:26 America/New_York | Link
Sancar Gazi
Kirill Kudriavtsev is right, you need to move the line
status = new Status(model.getRowCount());
one line up into the if-clause. Thanks anyhow, just what I needed.
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 08. Feb 2010, 11:13 America/New_York | Link
Magnus Tengdahl
Worked excellent for my needs, with the patch suggested by Sancar. Used it to display “,” between elements excluding the last one. Thanks!
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 04. Mar 2010, 12:17 America/New_York | Link
Florian Petersen
Hi everybody,
i configured the new version as stated but it seems that it is switched to the original ui:repeat version sometimes.
I use it in a search results page to distiguish the rows by evaluating varStatus.index. In this page there is a combo to select the results per page.
Everything works fine (e.g. paging) as long as i do not use the box. If i use it, the correct results are displayed, but all rows have the same color, which is the same effect as if i used the original ui:repeat that does not know varStatus.
Maybe the problem is the postback that the box does?!? But what is the solution? Page parameters are properly configured in corresponding pages.xml...
Every help is greatly appreciated,
thanks + best regards
Flo
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 04. Mar 2010, 12:54 America/New_York | Link
Paul Andreux
Hello,
I have found your UIRepeat patch and I am really excited because it will solv one of my big problem. Thanks for the job !
But, I have a problem. Taking your code I have a problem with two import:
import com.sun.facelets.tag.jsf.ComponentSupport;
import com.sun.facelets.util.FacesAPI;So I look on Seam lib, and I had jsf-facelets.jar and jsf-impl.jar in my EAR updating the class-path in the MANIFEST. It's compile well but when I launch the app, I have an exception:
Can't find resource for bundle java.util.PropertyResourceBundle, key el.convertI 'am using JBOSS AS 5.
I think I have some jar incompatibilities between SEAM jar and JBoss Jar. Can you list the Jar you used and where you put them ?
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 21. Apr 2010, 21:08 America/New_York | Link
Matt Wagner
If (like me) you don't have the luxury of modifying the Java-backing code that your facelet is working against, here's a workaround that helped me through what I was doing with ui:repeat - trying to comma-separate a list but omitting the comma after the final/last item.
Assume we have no varStatus:
<ui:repeat value="#{myCollection}" var="item">
<!-- want to output the comma-separated list of items here -->
</ui:repeat>You can use the “rendered=” attribute of h:outputText and compare the array metadata:
<ui:repeat value="#{myCollection}" var="item">
#{item}
<h:outputText value=", " rendered="#{myCollection.indexOf(item) < (myCollection.size - 1)}" />
</ui:repeat>Why the [size-1]? The .indexOf() call returns a 0-based value, ie the first item in your array is effectively myCollection[0], but the .size count starts at 1.
As a novice SEAM/facelet developer, I'm uncertain how expensive these operations are - make sure you have a way to profile performance of this code in your application before deciding it's the way to go - but if you're stuck in an implementation of facelets where varStatus isn't available, knowing that you can use .indexOf and .size as part of a “rendered=” condition within <ui:repeat> might just help you out of a jam.
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 05. May 2010, 07:27 America/New_York | Link
Stuart Campbell
@Flo,
You are correct: the component state is not completely restored on postback. Specifically, the varStatus attribute value is not saved or restored.
Here are the saveState/restoreState method changes I made, which seem to work:
public void restoreState(FacesContext faces, Object object) {
Object[] state = (Object[]) object;
super.restoreState(faces, state[0]);
this.childState = (Map) state[1];
this.offset = ((Integer) state[2]).intValue();
this.size = ((Integer) state[3]).intValue();
this.var = (String) state[4];
this.varStatus = (String) state[5];
this.value = state[6];
}
public Object saveState(FacesContext faces) {
return new Object[] {
super.saveState(faces),
this.childState,
new Integer(this.offset),
new Integer(this.size),
this.var,
this.varStatus,
this.value
};
}
Dieter - thanks for the solution!
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 19. Aug 2010, 07:18 America/New_York | Link
Pedro De Almeida
Hi Dieter, thanks for your implementation of varStatus!
I was also interested in using the from and to attributes but it seems that your component is only expecting Number types and my JSF environment provides String values, e.g.:
private int getFromValue() {
...
if (from instanceof Number) {
return ((Number) from).intValue();
} else {
return 0;
}
...
}So, I simply changed your getFromValue() and getToValue() methods like this:
private int getFromValue() {
Object from = this.from;
if (from == null) {
ValueBinding vb = this.getValueBinding("from");
if (vb != null) {
from = vb.getValue(FacesContext.getCurrentInstance());
}
}
if (from instanceof Number) {
return ((Number) from).intValue();
} else {
return 0;
}
}
private int getToValue() {
Object to = this.to;
if (to == null) {
ValueBinding vb = this.getValueBinding("to");
if (vb != null) {
to = vb.getValue(FacesContext.getCurrentInstance());
}
}
if (to instanceof Number) {
return ((Number) to).intValue();
} else if (to instanceof String) {
return Integer.valueOf(((String) to));
} else {
return -1;
}
}And it works nice now! Hope this will be helpfull to others... ;)
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 19. Aug 2010, 07:33 America/New_York | Link
Pedro De Almeida
Sorry, the method getFromValue() should be in fact:
private int getFromValue() {
Object from = this.from;
if (from == null) {
ValueBinding vb = this.getValueBinding("from");
if (vb != null) {
from = vb.getValue(FacesContext.getCurrentInstance());
}
}
if (from instanceof Number) {
return ((Number) from).intValue();
} else if (from instanceof String) {
return Integer.valueOf(((String) from));
} else {
return 0;
}
}
http://seamframework.org/Community/SolutionForUirepeatWithVarStatusAndNewParametersFromAndTo
Solution for ui:repeat with varStatus and new parameters "from" and "to" 07. Aug 2009, 08:25 America/New_York | Link
Dieter Rehbein
Since I needed a varStatus for ui:repeat, I've create my own version of the ui:repeat tag, which has the following new features:
It now supports the attribute “varStatus”. The status object has the following attributes:
■index: the current - zero based - index
■count: the number of iterations. If the count is not available (e.g. for variables of type ResultSet): -1
■last: true, if the current iteration is the last one
■first: true, if the current iteration is the first one
■from, to: for simple for-loops without a collection
example 1:
<ui:repeat value="#{myCollection}" var="item" varStatus="status">
<h:outputText value="...." rendered="#{status.first}"/>
<h:outputText value="...." rendered="#{status.index gt 5}"/>
.......
</ui:repeat>
example 2:
<ui:repeat var="i" varStatus="status" from="5" to="7">
value: #{i}<br/>
index: #{status.index}<br/>
</ui:repeat>
The second example renders the following output:
value: 5
index: 0
value: 6
index: 1
value: 7
index: 2The sourcecode for the new version of the class UIRepeat can be downloaded from here (unfortunately this forum does not support file uploads).
To use it, you have to add a new entry to the file WEB-INF/faces-config.xml:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="1.2"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<!-- this component entry is new: -->
<component>
<component-type>facelets.ui.Repeat</component-type>
<component-class>com.alturos.gui.facelets.UIRepeat</component-class>
</component>
<application>
<locale-config>
<default-locale>de</default-locale>
<supported-locale>cs</supported-locale>
<supported-locale>de</supported-locale>
<supported-locale>en</supported-locale>
<supported-locale>fr</supported-locale>
<supported-locale>it</supported-locale>
<supported-locale>ru</supported-locale>
</locale-config>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
</faces-config>
Tags: facelets
12 Replies:
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 07. Aug 2009, 08:27 America/New_York | Link
Dieter Rehbein
sorry, there are some mistakes in the previous post:
the status object provides the following attributes:
■index
■count
■last
■first
The tag has the following new attributes:
■from
■to
The attribute varStatus already existed but it was not used by the original UIRepeat version.
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 23. Nov 2009, 22:12 America/New_York | Link
Kirill Kudriavtsev
hi, thanks for this solution
but in your class exist a little mistake (i found at least one) your code
private synchronized DataModel getDataModel()
{
if(this.model == null)
{
...
}
status = new Status(model.getRowCount());
return this.model;
}
should be
private synchronized DataModel getDataModel()
{
if(this.model == null)
{
...
status = new Status(model.getRowCount());
}
return this.model;
}
otherwise varStatus.index doesn't work
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 26. Jan 2010, 16:55 America/New_York | Link
Dmitri Ilyin
Hi,
i would also need a varStatus attribute.
Dieter, i've tried your solution and could not get it work. The status.index stays empty.
have you already used your Tag in you projects? May be you have already a fixed vertion. Or a tip how to get it work.
The Tag would be very usefull.
thanks a lot regards
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 04. Feb 2010, 15:34 America/New_York | Link
Emanuel Palacio
Worked fine for me. Thanks a lot Dieter!
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 06. Feb 2010, 17:26 America/New_York | Link
Sancar Gazi
Kirill Kudriavtsev is right, you need to move the line
status = new Status(model.getRowCount());
one line up into the if-clause. Thanks anyhow, just what I needed.
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 08. Feb 2010, 11:13 America/New_York | Link
Magnus Tengdahl
Worked excellent for my needs, with the patch suggested by Sancar. Used it to display “,” between elements excluding the last one. Thanks!
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 04. Mar 2010, 12:17 America/New_York | Link
Florian Petersen
Hi everybody,
i configured the new version as stated but it seems that it is switched to the original ui:repeat version sometimes.
I use it in a search results page to distiguish the rows by evaluating varStatus.index. In this page there is a combo to select the results per page.
Everything works fine (e.g. paging) as long as i do not use the box. If i use it, the correct results are displayed, but all rows have the same color, which is the same effect as if i used the original ui:repeat that does not know varStatus.
Maybe the problem is the postback that the box does?!? But what is the solution? Page parameters are properly configured in corresponding pages.xml...
Every help is greatly appreciated,
thanks + best regards
Flo
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 04. Mar 2010, 12:54 America/New_York | Link
Paul Andreux
Hello,
I have found your UIRepeat patch and I am really excited because it will solv one of my big problem. Thanks for the job !
But, I have a problem. Taking your code I have a problem with two import:
import com.sun.facelets.tag.jsf.ComponentSupport;
import com.sun.facelets.util.FacesAPI;So I look on Seam lib, and I had jsf-facelets.jar and jsf-impl.jar in my EAR updating the class-path in the MANIFEST. It's compile well but when I launch the app, I have an exception:
Can't find resource for bundle java.util.PropertyResourceBundle, key el.convertI 'am using JBOSS AS 5.
I think I have some jar incompatibilities between SEAM jar and JBoss Jar. Can you list the Jar you used and where you put them ?
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 21. Apr 2010, 21:08 America/New_York | Link
Matt Wagner
If (like me) you don't have the luxury of modifying the Java-backing code that your facelet is working against, here's a workaround that helped me through what I was doing with ui:repeat - trying to comma-separate a list but omitting the comma after the final/last item.
Assume we have no varStatus:
<ui:repeat value="#{myCollection}" var="item">
<!-- want to output the comma-separated list of items here -->
</ui:repeat>You can use the “rendered=” attribute of h:outputText and compare the array metadata:
<ui:repeat value="#{myCollection}" var="item">
#{item}
<h:outputText value=", " rendered="#{myCollection.indexOf(item) < (myCollection.size - 1)}" />
</ui:repeat>Why the [size-1]? The .indexOf() call returns a 0-based value, ie the first item in your array is effectively myCollection[0], but the .size count starts at 1.
As a novice SEAM/facelet developer, I'm uncertain how expensive these operations are - make sure you have a way to profile performance of this code in your application before deciding it's the way to go - but if you're stuck in an implementation of facelets where varStatus isn't available, knowing that you can use .indexOf and .size as part of a “rendered=” condition within <ui:repeat> might just help you out of a jam.
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 05. May 2010, 07:27 America/New_York | Link
Stuart Campbell
@Flo,
You are correct: the component state is not completely restored on postback. Specifically, the varStatus attribute value is not saved or restored.
Here are the saveState/restoreState method changes I made, which seem to work:
public void restoreState(FacesContext faces, Object object) {
Object[] state = (Object[]) object;
super.restoreState(faces, state[0]);
this.childState = (Map) state[1];
this.offset = ((Integer) state[2]).intValue();
this.size = ((Integer) state[3]).intValue();
this.var = (String) state[4];
this.varStatus = (String) state[5];
this.value = state[6];
}
public Object saveState(FacesContext faces) {
return new Object[] {
super.saveState(faces),
this.childState,
new Integer(this.offset),
new Integer(this.size),
this.var,
this.varStatus,
this.value
};
}
Dieter - thanks for the solution!
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 19. Aug 2010, 07:18 America/New_York | Link
Pedro De Almeida
Hi Dieter, thanks for your implementation of varStatus!
I was also interested in using the from and to attributes but it seems that your component is only expecting Number types and my JSF environment provides String values, e.g.:
private int getFromValue() {
...
if (from instanceof Number) {
return ((Number) from).intValue();
} else {
return 0;
}
...
}So, I simply changed your getFromValue() and getToValue() methods like this:
private int getFromValue() {
Object from = this.from;
if (from == null) {
ValueBinding vb = this.getValueBinding("from");
if (vb != null) {
from = vb.getValue(FacesContext.getCurrentInstance());
}
}
if (from instanceof Number) {
return ((Number) from).intValue();
} else {
return 0;
}
}
private int getToValue() {
Object to = this.to;
if (to == null) {
ValueBinding vb = this.getValueBinding("to");
if (vb != null) {
to = vb.getValue(FacesContext.getCurrentInstance());
}
}
if (to instanceof Number) {
return ((Number) to).intValue();
} else if (to instanceof String) {
return Integer.valueOf(((String) to));
} else {
return -1;
}
}And it works nice now! Hope this will be helpfull to others... ;)
Re: Solution for ui:repeat with varStatus and new parameters "from" and "to" 19. Aug 2010, 07:33 America/New_York | Link
Pedro De Almeida
Sorry, the method getFromValue() should be in fact:
private int getFromValue() {
Object from = this.from;
if (from == null) {
ValueBinding vb = this.getValueBinding("from");
if (vb != null) {
from = vb.getValue(FacesContext.getCurrentInstance());
}
}
if (from instanceof Number) {
return ((Number) from).intValue();
} else if (from instanceof String) {
return Integer.valueOf(((String) from));
} else {
return 0;
}
}
http://seamframework.org/Community/SolutionForUirepeatWithVarStatusAndNewParametersFromAndTo
发表评论
-
seam前端提速
2010-09-08 13:11 1349Seam使用了richfaces做为jsf ... -
maven 中使用jetty 改端口号
2010-08-04 13:52 1370jetty 使用时,如果出现 address already ... -
seam空格
2010-07-23 09:59 685seam空格:&nbps;没用 ,要使用 ... -
null value seam
2010-07-23 09:33 511因为给model添加一个double类型的字段(数据库已有一些 ... -
Seam el 中使用 map
2010-06-29 15:23 1257一直以为在el里不能用map,今天发现原来可以... @na ... -
seam pdf The document has no pages
2010-06-28 13:31 1738用seam 中的pdf功能时 出现The document h ... -
JSF多对多增加
2010-06-25 17:04 891多对多关系时 person (n-n) work (perso ... -
JSF Chapter04
2010-06-24 13:18 1496. 用队列控制 Event Traffic ... -
JSF Chapter11
2010-06-24 13:14 8331. 使用内建的 Skins 1) 基 ... -
JSF Chapter10
2010-06-24 13:13 1158. <rich:scrollableDataT ... -
JSF Chapter09
2010-06-24 11:35 9911. <rich:dropDownM ... -
JSF Chapter08
2010-06-24 11:34 12811. <rich:pickList> ... -
JSF Chapter07
2010-06-24 11:34 15641. 常用的 dataTable 类的控件有: l ... -
JSF Chapter06
2010-06-24 11:20 1713. <rich:panel> 1) ... -
JSF Chapter05
2010-06-24 11:18 16491. a4j: 提供了页面级的 Ajax 支持,也 ... -
JSF Chapter03
2010-06-24 11:14 1464本章主要包括三方面内 ... -
JSF Chapter02
2010-06-24 11:13 9311. 配置 RichFaces 1) ... -
JSF Chapter01
2010-06-24 11:12 9021. JSF’s View = UICompone ... -
JSF Chapter04(频繁调用控件)
2010-06-24 11:06 13281. <!-- [end ... -
Property '****' is not writable on type
2010-04-28 22:20 1079再用seam+jsf开发的时候冒出:***Edit.xhtml ...
相关推荐
seam_carving代码实现 图像缩放
seam in action seam in action seam in action seam in action seam in action seam in action seam in action
Seam 是一种业级 企 Java 的应规用程序框架。它的灵感源自下列原 : 只有一种“工具” Seam为 应 业务业业 义 种统 组 你的 用程序中所有的 定 了一 一的 件模型。 Seam组件可能是 态义 关关 态 有状 的,包含与几...
JBOSS_SEAM配置
seam级联菜单例子
seam资料seam资料seam资料seam资料seam资料seam资料seam资料seam资料
seam carving的相关代码实现
JBoss Seam JBoss Seam JBoss Seam
seam介绍
SeamCarving的C++实现代码,使用opencv库。包含完整项目工程及测试图像,可直接使用
seam下一代web开发框架
Jboss Seam in ActionJboss Seam in ActionJboss Seam in ActionJboss Seam in ActionJboss Seam in Action
seam 中文文档 pdf 格式 JSF+EJB3.0快速开发框架Seam的中文版向导。。。
seam框架需要的所有jar包,支持seam ui组件
JBOSS SEAM组件中文手册 Seam_2.0_Reference_zh_CN
seam中的注解总结,包括三种JPA和seam自身的标签
Seam - 语境相关的组件[满江红20071230]............................................................................................................................ 1 Java EE 框架...........................
Seam 中文开发指南 seam中文文档
Seam - 语境相关的组件 ,学习seam的好资料.
Seam全称是Jboss Seam,是一个Java EE 5框架。它通过把JSF与EJB3.0组件合并在一起,以及利用JDK5.0的Annotation技术,从而为开发基于Web的企业应用程序提供一个最新的模式。