- 浏览: 417106 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
zxjlwt:
学习了http://surenpi.com
java.lang.LinkageError解决办法。 -
zqb666kkk:
/**
*
* @param filepath
...
Java删除目录及目录下的所有文件 -
zqb666kkk:
f.exists() && f.isDirec ...
Java删除目录及目录下的所有文件 -
coldrain2014:
在线api文档 http://online.code1314. ...
JavaMail java.lang.NullPointerException -
timeroading1:
chxkyy 写道xx175194716 写道真佩服,把jar ...
Activiti 学习记录3 之Activiti源代码及默认h2数据库连接
问题提出:
平台:Richfaces,Jsf,Spring,Ejb3.0
- 页面文件:
<h:selectOneListbox size="1" value="#{coalDailyBackBean.currentEntity.coalDaily.coalTS}" converter="com.mycompany.CoalTransportStyleConverter"> <f:selectItems value="#{coalDailyBackBean.allTSs}"> </f:selectItems> </h:selectOneListbox>
coalTS是一个CoalTransportStyle的对象
allTSs是一个CoalTransportStyle的List
- JSF配置文件faces-config.xml:
<converter> <converter-id> com.mycompany.CoalTransportStyleConverter </converter-id> <converter-class> com.mycompany .parameter.plantinfo.web.converter.CoalTransportStyleConverter </converter-class> </converter>
CoalTransportStyle.java
@Entity @Table(name = "T_CoalTransportStyle") public class CoalTransportStyle implements Serializable { /** * */ private static final long serialVersionUID = -5090574246490412429L; private Long id; private String paraName; @Id @GeneratedValue(strategy=GenerationType.AUTO) public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Column(unique=true,nullable=false) public String getParaName() { return paraName; } public void setParaName(String paraName) { this.paraName = paraName; } }
public class CoalTransportStyleConverter implements Converter { public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) { CoalTransportStyle style = new CoalTransportStyle(); String strs[] = arg2.split(":"); style.setId(new Long(strs[0])); style.setParaName(strs[1]); return style; } public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) { CoalTransportStyle style = (CoalTransportStyle) arg2; return style.getId() + ":" + style.getParaName(); } }
定义了一个converter
- 后台支撑Bean:
/** * 获得所有的运输方式 * * @return the allTSs */ public List<SelectItem> getAllTSs() { allTSs = new ArrayList<SelectItem>(); List<CoalTransportStyle> list = coalTransportStyleService.queryAll( "paraName", true); for (CoalTransportStyle style : list) { allTSs.add(new SelectItem(style, style.getParaName())); } return allTSs; }
/** * @return the currentEntity */ public CoalDailyEntity getCurrentEntity() { if (getCoalDailyId() != null) { currentEntity = new CoalDailyEntity(); currentEntity.setPlant(plant); currentEntity.setT_Date(date);// 设置时间 currentEntity.setCoalDaily(coal); } return currentEntity; }
初始页面显示时,h:selectOneListbox显示没有问题,但是当数据提交时,就报了一个错:Validation Error: Value is not valid 上网找了半天也没找到答案,后来自己调试了一下。 - 当数据提交时,是调用了CoalTransportStyleConverter的getAsObject说明这个对象已经创建起来了。但是为什么还报这个错误呢?
- 于是我找了Messages_en.properties错误信息文件。
javax.faces.component.UISelectOne.INVALID={0}: Validation Error: Value is not valid
- 又找到UISelectOne的validateValue方法。
protected void validateValue(FacesContext context, Object value) { // Skip validation if it is not necessary super.validateValue(context, value); if (!isValid() || (value == null)) { return; } // Ensure that the value matches one of the available options boolean found = matchValue(value, new SelectItemsIterator(this)); // Enqueue an error message if an invalid value was specified if (!found) { FacesMessage message = MessageFactory.getMessage(context, INVALID_MESSAGE_ID, MessageFactory.getLabel(context, this)); context.addMessage(getClientId(context), message); setValid(false); } } // --------------------------------------------------------- Private Methods /** * <p>Return <code>true</code> if the specified value matches one of the * available options, performing a recursive search if if a * {@link SelectItemGroup} instance is detected.</p> * * @param value {@link UIComponent} value to be tested * @param items Iterator over the {@link SelectItem}s to be checked */ private boolean matchValue(Object value, Iterator items) { while (items.hasNext()) { SelectItem item = (SelectItem) items.next(); if (item instanceof SelectItemGroup) { SelectItem subitems[] = ((SelectItemGroup) item).getSelectItems(); if ((subitems != null) && (subitems.length > 0)) { if (matchValue(value, new ArrayIterator(subitems))) { return (true); } } } else { //Coerce the item value type before comparing values. Class type = value.getClass(); Object newValue; try { newValue = getFacesContext().getApplication(). getExpressionFactory().coerceToType(item.getValue(), type); } catch (ELException ele) { newValue = item.getValue(); } catch (IllegalArgumentException iae) { // If coerceToType fails, per the docs it should throw // an ELException, however, GF 9.0 and 9.0u1 will throw // an IllegalArgumentException instead (see GF issue 1527). newValue = item.getValue(); } if (value.equals (newValue)) { return (true); } } } return (false); }
这里调用了equals方法,结果是不行,所以抛出了这个异常。 - 重写CoalTransportStype的equals方法即可:
@Entity @Table(name = "T_CoalTransportStyle") public class CoalTransportStyle implements Serializable { /** * */ private static final long serialVersionUID = -5090574246490412429L; private Long id; private String paraName; @Id @GeneratedValue(strategy=GenerationType.AUTO) public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Column(unique=true,nullable=false) public String getParaName() { return paraName; } public void setParaName(String paraName) { this.paraName = paraName; } public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final CoalTransportStyle other = (CoalTransportStyle) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; if (paraName == null) { if (other.paraName != null) return false; } else if (!paraName.equals(other.paraName)) return false; return true; } }
发表评论
-
richfaces ajax特性的一点小提示(为什么数据传不到后台去?)
2008-06-25 11:22 2076问题描述: 页面文件: <h:outputText va ... -
<f:selectItems>空值问题
2008-06-24 11:49 3023报错的代码: java.lang.NullPointerExc ... -
richfaces3.1.2升级到3.2.1中遇到的问题。
2008-06-05 11:55 13821。org.richfaces.component.UIDat ... -
rich:modalPanel 与 form的关系
2008-05-27 17:00 1720<rich:modalPanel>不能放在form ... -
richfaces3.1.2 modalPanel文档的一点小bug
2008-05-27 14:57 2740在richfaces_reference.pdf P298 原 ... -
<f:convertDateTime> 时间显示不对问题
2008-04-21 10:49 7324在输出日期时,在Java里java.util.Date类型的对 ... -
xhtml下用jsp标签方法
2008-04-16 13:41 25411- use f:verbatim jsf tag 2- u ... -
JSF VS Tapestry 全面比较
2008-04-16 13:26 2094目 前应用很广泛而且也很成熟的Struts应用开发框架, ... -
RichFaces <a4j:commandButton>传参数
2008-03-27 17:00 5521转自:http://livedemo.exadel.com/r ... -
jsf参数传递2
2008-03-27 12:48 7为了避免使用Session的一 ... -
JSF本地化过程中出现乱码问题解决
2008-03-26 13:05 2866JSF本地化的基本配置。首先要在faces-config.xm ... -
augmentIdReference 错误
2008-03-24 14:08 1208把HtmlMessage写在后台的BackBean如下所示: ... -
如何创建自定义验证器?
2008-03-21 14:46 1650下面是一个email验证器的示例: EmailValida ... -
JSF 生命周期总结
2008-02-01 08:53 3221当一个http 请求来临的时候,首先会调用FacesServl ... -
JSF Id冲突解决办法
2008-02-01 08:46 1847在jsf中,页面组件如果是由页面标签与后台的程序一起生成的话, ... -
Ajax4jsf 和 <h:message> 一起使用时候的问题
2008-01-21 10:23 3385如果在页面中使用了<a4j:commandButton& ... -
jsf页面参数的传递及加载数据(转)
2008-01-16 16:29 4197转自:http://www.blogjava.net/ ... -
richfaces调试方法
2008-01-14 17:43 1775用到<a4j:log>这个标签示例如下:<a ... -
JSF+Facelets+Tomahawk的笔记(转贴)
2008-01-08 16:23 1494转自:http://www.cnblogs.com/phoen ... -
facelets.DEVELOPMENT作用。
2008-01-07 18:21 1807facelets.DEVELOPMENT 不是必需的,但是它允 ...
相关推荐
jsf之验证源码jsf-validation.zip
JSF2.0实战 - 7、自定义<h:head>源代码
jsf2.0 整合了ajax,这个是英文文档来的
JSF-1_1-API.chm
JSF开发所必需包:花了很长时间才收集好,很费时,现已收集好,何不分享给大家,让大家节省时间做点有意义的事情呢?呵呵。。。已在附件供大家下载,若是你所需要的东西,那就请投个票、说句鼓励的话,我就满足了。 ...
JSF-UIREPEAT 亲测可试 源代码
本人用的是Myeclipse7.0+J2EE5.0+JSF开发,配置myfaces各种jar,包括上传.考到lib下就可以.哪里不明加我QQ问我 200808006
JSF的学习入门知识教程,里面有例子还有各个标签的使用及属性介绍
jsf2.0数据校验,文档为英文,.. • Manual validation – Validation in the action controller method • Implicit automatic validation Tidh“id”ib – Type conversion and the “required” attribute • ...
目录 此示例应用程序仅展示了如何通过针对执行 JSF 请求。 运行它 mvn gatling:execute ... val jsfViewStateCheck = css( " input[name='javax.faces.ViewState'] " , " value " ) .saveAs( " viewState " )
JSF组件,允许对JSF应用程序使用v1.4.2编辑器。 特征 开箱即用的支持162种模式 开箱即用,支持38种模式 emacs和vim的按键绑定 将Ace会话保留到JSF支持bean: 代码折叠 滚动 设定选项 支持 用法 在facelets页面中,...
e-commerce-jsf-tjw:电子商务计划Java实用程序JSF门户网站Java门户网站
JSF Primefaces教程 该存储库包含发布的JSF Primefaces示例的所有源代码。 如有疑问或评论,请在各自的博客文章中发表评论或打开GitHub问题。 谢谢!
JSF 和 Spring 集成 本实验展示了如何设置 JSF 了解 Spring 组件以使用 Spring 依赖注入。 它是用 Maven 构建的,它使这个项目与 IDE 无关。 因此,构建和运行它很简单: mvn 全新安装 mvn码头:运行 然后,在某个 ...
高JSF弹簧高JSF弹簧幻灯片共享: ://es.slideshare.net/odraudek99/taller-integracion-jsf-spring
jsf-primefaces JSF com PrimeFaces
本文档旨在描述Java EE平台的JavaServer Faces(JSF)框架的要点,并且还旨在展示在Tomcat应用程序服务器上部署的具有Hibernate,PrimeFaces和Maven的基础项目。 有关更多信息,建议参考。 联合部队 JavaServer ...
目前网上罕见的JSF+iBATIS+MySQL示例代码,公司某软件项目所需而做的前期DEMO,只有两个Web页面,用户登录和用户列表,但已经能够说明JSF+iBATIS的典型应用方式。 MyEclipse6.5 项目工程文件,内含SQL建库指令。 ...
火龙果软件工程技术中心 本文内容包括:Ajax的优势和缺点如何用JSF组件应用Ajax如何为现有JSF应用程序增加Ajax其他使用RationalApplicationDeveloperAjax工具的方式下载参考资料Ajax是当今互联网上最流行的技术,...