`
wangzl2222
  • 浏览: 150920 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

seam topic

阅读更多
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) &lt; (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
分享到:
评论

相关推荐

    jboss seam 学习资料,seam in action和官方手册

    **JBoss Seam 学习资源概述** JBoss Seam 是一个开源的应用程序框架,它整合了JavaServer Faces (JSF)、Enterprise JavaBeans (EJB)、Java Persistence API (JPA) 和其他Java EE技术,旨在简化开发过程,提高开发...

    seam_carving 代码实现 seam

    **Seam Carving 技术详解** Seam Carving,又称图像拉链,是一种基于能量最小化的图像调整方法,主要用于图像大小的动态调整,而不仅仅是简单的等比例缩放。它能够在保持图像主要结构不变的情况下,根据需要增加或...

    Seam框架文档简述

    ### Seam框架核心知识点详解 #### 一、Seam框架简介 Seam,全称为JBoss Seam,是一款基于Java EE 5的技术栈构建的应用框架。它通过整合JSF(JavaServer Faces)与EJB 3.0(Enterprise JavaBeans 3.0)组件,并充分...

    JBOSS SEAM组件中文手册

    **JBoss Seam组件中文手册** **一、Seam框架概述** Seam是一个开源的企业级Java框架,由JBoss公司开发,旨在简化Java EE应用程序的开发。它将多种技术如JavaServer Faces (JSF),Java Persistence API (JPA),EJB 3...

    为Seam做好准备

    "为Seam做好准备"这个标题暗示我们即将探讨的是关于Seam框架的入门与准备工作。Seam是一个Java EE集成框架,它将JavaServer Faces(JSF)、Java Persistence API(JPA)、Enterprise JavaBeans(EJB)3.0以及其他...

    seam in action 中文 english

    《Seam in Action》是一本专门探讨Seam框架的书籍,该书分为中文和英文两个版本,对于初学者和有经验的开发者来说都是一个宝贵的资源。Seam是一个强大的Java EE框架,它集成了多种技术,如JavaServer Faces (JSF)、...

    seam_in_action

    根据提供的信息,我们可以推断出这是一本关于 Seam 框架的专业书籍,书名为《Seam in Action》,作者为 Dan Allen 和 Manning 出版社出版。本书主要讲解了 Seam 框架在 Java EE 3 环境中的应用与开发实践。接下来将...

    MATLAB_Seam_Carving_seamcarving_

    MATLAB_Seam_Carving_seamcarving_ 是一个与图像处理相关的项目,主要涉及到一种称为“seam carving”的技术,这是一种动态图像调整大小的方法,它可以在不改变图像整体视觉效果的情况下,增加或减少图像的宽度和...

    Seam security

    Seam Security是针对Java Web应用程序的安全框架,它是JBoss Seam项目的一部分,提供了全面的安全解决方案,包括身份验证、授权和身份管理等功能。Seam Security以易于配置和使用为特点,允许开发者快速设置应用程序...

    Jboss Seam中文版

    ### JBoss Seam中文版知识点详解 #### JBoss Seam简介 JBoss Seam是一个强大的企业级应用开发框架,基于Java EE标准,特别强调简化Web应用的开发流程。它通过整合多种技术如JSF、EJB 3.0等,提供了一种更为高效、...

    seam参考手册中文版

    ### Seam参考手册中文版知识点概览 #### 一、Seam简介及基本概念 ##### JBoss Seam概述 - **Seam**是JBoss家族中的一员,它是一个建立于Java EE平台之上的开源框架,旨在简化企业级应用的开发过程。 - **版本**: ...

    seam需要的jar包

    Seam框架是一个全面的Java企业级应用开发框架,它整合了JSF(JavaServer Faces)、EJB、CDI(Contexts and Dependency Injection)以及许多其他Java EE技术,为开发者提供了强大的组件模型和丰富的功能,旨在简化...

    SEAM 中文开发指南

    ### SEAM 中文开发指南知识点概述 #### 一、SEAM 框架简介 - **SEAM**:SEAM 是一个基于 Java EE 的企业级应用框架,它简化了复杂的应用程序开发过程,并且提供了丰富的功能来支持业务逻辑的实现。 - **版本信息**...

    Seam Carving的C++实现代码

    Seam Carving是一种图像内容感知的尺寸调整方法,它能够在保持图像主要结构不变的情况下,智能地减少或增加图像的宽度和高度。这种方法是由Amit Agarwal和Matthieu Salzmann于2007年提出的,其核心思想是通过找到...

    seam的注解和标签

    Seam是一个Java EE框架,它将JavaServer Faces(JSF)、Java Persistence API(JPA)、Inversion of Control(IoC)和Enterprise JavaBeans(EJB)等技术融合在一起,为开发复杂的Web应用程序提供了便利。在Seam框架...

    Seam - 语境相关的组件

    Seam是一种Java EE框架,它在开发企业级应用程序时提供了高度集成和语境相关的组件模型。这个框架的主要目标是简化复杂性,使开发者能够更高效地构建动态、响应式的Web应用。Seam的核心理念是将不同的技术,如Java...

    jboss-seam2.0文档

    【JBoss Seam 2.0文档详解】 JBoss Seam 是一个开源的企业级开发框架,它旨在简化Java EE应用的开发过程,特别是在Web和富互联网应用程序(Rich Internet Applications, RIA)领域。Seam 2.0是其重要的版本,提供了...

    seam级联菜单例子

    Seam是一个开源的Java EE框架,它将JavaServer Faces(JSF)与EJB3、Hibernate等技术结合在一起,提供了一种更为简化的企业级开发方式。在这个“seam级联菜单例子”中,我们将深入探讨如何在Seam应用中实现级联选择...

    jboss-seam2.1

    Seam 是一种业级 企 Java 的应规用程序框架。它的灵感源自下列原 : 只有一种“工具” Seam为 应 业务业业 义 种统 组 你的 用程序中所有的 定 了一 一的 件模型。 Seam组件可能是 态义 关关 态 有状 的,包含与几...

    JBoss Seam

    《JBoss Seam:超越Java EE的简易与强大》是一本深度探索JBoss Seam框架的权威著作,由Michael Yuan和Thomas Heute共同撰写。本书聚焦于JBoss Seam框架,旨在为读者提供一个全面、深入的理解,以掌握其在企业级应用...

Global site tag (gtag.js) - Google Analytics