OmniFaces 1.6.1的必填字段 [英] Required fields with OmniFaces 1.6.1

查看:111
本文介绍了OmniFaces 1.6.1的必填字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Primefaces 3.5.16,JBoss 7.2.0,PE 0.7.1,Mojara 2.1.26,WELD-000900 1.1.10(最终版) Web.xml具有一些配置功能,faces-config具有已定义的语言包.

Primefaces 3.5.16, JBoss 7.2.0, PE 0.7.1, Mojara 2.1.26, WELD-000900 1.1.10 (Final) Web.xml has some configuration stuff, faces-config has languages bundles defined.

我有以下对话框,其中包含一些输入字段和p:tabview:

I have following dialog with some input fields and p:tabview:

<p:dialog>

  <h:form>
   <p:tabView binding="#{tabViewEL}"> 
    <p:messages autoUpdate="true"/> 
  <p:tab  title="tab1">

    <p:inputText value="#{bean.value1}" required="true" />
    <p:inputText value="#{bean.value2}" />
    <p:selectOneMenu value="#{bean.value3}">
       <f:selectItems value="#{bean.items1}"></f:selectItems>
    </p:selectOneMenu>
  </p:tab>
  <p:tab> ... </p:tab>
  </p:tabView>

  <p:commandButton value="ok" oncomplete="checkAndHide(xhr, status, args);" action="#{bean.action()}"/>
  </h:form>

</p:dialog>

如果我单击确定",并且正在使用OmniFaces v.1.5或1.6,则它的功能正确.如果我使用1.6.1,则所有必填字段(和p:selectOneMenu不带null-selected-Item)都标记为红色,并显示错误必须输入值".如何使用1.6.1且没有验证错误?

If I click "ok" and I am using OmniFaces v. 1.5 or 1.6 it functions right. If I'm using 1.6.1 all required fields (and p:selectOneMenu without null-selected-Item) are marked red with errors "Value is required". How can I use 1.6.1 without validation errors ?

编辑 :我试图创建一个示例,但发现了应用程序的另一种奇怪行为.在OmniFaces 1.6中,它可以正常运行,但在1.6.1中,输入字段未填充值.

Edit : I've tried to create an example but I've discovered another curious behavior of application. With OmniFaces 1.6 it functions right, but with 1.6.1 the input fields are not filled with values.

 OmnitestBean.java
 import java.io.Serializable;

 import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
 import javax.inject.Named;

 @Named
 @SessionScoped
 public class OmnitestBean implements Serializable{
private Integer value1 = 12;
private Integer value2 = 3;

public OmnitestBean (){
    System.out.println("Constru");
}

@PostConstruct
public void a(){
    value1 = 14;
    value2 = 30;
    System.out.println("in postconstruct");
}

public Integer getValue1() {
    return value1;
}

public void setValue1(Integer value1) {
    this.value1 = value1;
}

public Integer getValue2() {
    return value2;
}

public void setValue2(Integer value2) {
    this.value2 = value2;
}

public void action(){
    System.out.println("In action");
}

 }

omnifaces.xhtml:

omnifaces.xhtml:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"    xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
xmlns:fn="http://java.sun.com/jsp/jstl/functions" 
xmlns:pe="http://primefaces.org/ui/extensions">
<h:head />
<body>
<h:form id="editPopForm">
    <p:messages id="messages2" autoUpdate="true"></p:messages>
    <p:inputText value="#{omnitestBean.value1}" required="true" />
    <p:inputText value="#{omnitestBean.value2}" />

    <p:commandButton process="@form" action="#{omnitestBean.action()}" value="OK"
         update="@form" id="editFormOkButt" />
</h:form>

推荐答案

正如BalusC在他的评论中指出的,它与Integer转换器有关. 我有以下虚拟整数转换器,它隐藏在项目中的某个位置.

As BalusC noted in his comment it has something to do with Integer converter. I had the following dummy integer converter, it was hidden somewhere in project.

@FacesConverter(value = "someDummyConverter")
public class SomeDummyConverter extends IntegerConverter {
public Object getAsObject(FacesContext context, UIComponent component,
        String value) {
    Integer intValue = (Integer) super.getAsObject(context, component, value);
    return intValue;
}

@Override
public String getAsString(FacesContext context, UIComponent component, Object o) {
    return null;
}

}

如果我使用OmniFaces 1.5或1.6,则不会调用此转换器.使用OmniFaces 1.6.1、1.6.2、1.6.3调用了转换器.如果我删除了转换器,问题就消失了.

If I used OmniFaces 1.5 or 1.6 this converter was not called. With OmniFaces 1.6.1, 1.6.2, 1.6.3 the converter was called. If I deleted the converter, the problem was disappeared.

这篇关于OmniFaces 1.6.1的必填字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆