Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 显示下拉框时出错?_Jsf 2_Primefaces - Fatal编程技术网

Jsf 2 显示下拉框时出错?

Jsf 2 显示下拉框时出错?,jsf-2,primefaces,Jsf 2,Primefaces,我正在开发prime faces 3.5的最新版本。 问题:每当ajax更新发生时,都会启用所需的true <p:column> <h:outputText value="Your Birth Date " style="width:50%"/> </p:column> <p:column> <p:selectOneMenu required="true" id="inputMonth" value="#{createProfile.

我正在开发prime faces 3.5的最新版本。 问题:每当ajax更新发生时,都会启用所需的true

<p:column>
    <h:outputText value="Your Birth Date " style="width:50%"/>
</p:column>
<p:column>
<p:selectOneMenu required="true" id="inputMonth"
value="#{createProfile.dateUtils.inputMonth}"
requiredMessage="Invalid Month."        
style="width:28%;text-align:left;" 
tabindex="4" 
label="Month" 
height="355">
    <f:selectItem itemLabel="MM" itemValue="" />
    <f:selectItems value="#{createProfile.dateUtils.monthList}" />
    <p:ajax update="inputDay" listener="#{createProfile.dateUtils.loadDays}">
</p:selectOneMenu>

<p:selectOneMenu  required="true" id="inputDay"
value="#createProfile.dateUtils.inputDay}"
requiredMessage="Invalid Date."
style="width:28%;text-align:left;"
tabindex="5"
label="Day"
height="355">
    <f:selectItem itemLabel="DD" itemValue="" />
    <f:selectItems value="#{createProfile.dateUtils.dayList}" />
    <p:ajax />
</p:selectOneMenu>

<p:selectOneMenu required="true" id="inputYear"
value="#{createProfile.dateUtils.inputYear}"
requiredMessage="Invalid Year."
style="width:34%;text-align:left;" tabindex="6"
label="Year" height="455">
    <f:selectItem itemLabel="YYYY" itemValue="" />
    <f:selectItems value="#{createProfile.dateUtils.yearList}" />
    <p:ajax update="inputDay" listener="#{createProfile.dateUtils.loadDays}" />
</p:selectOneMenu>
</p:column>

当从下拉列表中选择一个月时,它将使用ajax调用填充day字段,并根据所选的月份加载日期,因为day字段上设置了required=“true”,因此当天的文本框将从默认颜色更改为红色,当我们选择年份时也会发生类似的情况。只有当我尝试提交表单时,才会进行验证

dateutils.java

public class DateUtils {

private Map<String,String> monthList;
private Map<String,String> dayList;
private Map<String,String> yearList;
private String inputYear="";
private String inputMonth="";
private String inputDay="";

/**
 * Method to get the Month List.
 * @return monthList
 */
public Map<String, String> getMonthList() {
    this.monthList  =new TreeMap<String, String>();
    //this.monthList = new HashMap<String, String>();
    for(int i=1;i<=12;i++){
        String monthIndex = i<=9?"0"+i:""+i;
        this.monthList.put(monthIndex, monthIndex);
    }
    //monthList = sortByComparator(monthList);
    return monthList;
}
/**
 * Method to set the Month List.
 * @param monthList
 */
public void setMonthList(Map<String, String> monthList) {
    this.monthList = monthList;
}
/**
 * method to get the day list.
 * @return dayList
 */
public Map<String, String> getDayList() {
    return dayList;
}
/**
 * method to set the Day List.
 * @param dayList
 */
public void setDayList(Map<String, String> dayList) {
    this.dayList = dayList;
}
/**
 * Method to get the yearList.
 * @return yearList
 */
public Map<String, String> getYearList() {
    //this.yearList = new HashMap<String, String>();
    this.yearList =new TreeMap<String, String>(Collections.reverseOrder());  
    Calendar cal = Calendar.getInstance();
    int yyyy = cal.get(Calendar.YEAR);
    for(int i=yyyy-18; i>=(yyyy-112); i--){
        this.yearList.put(""+i, ""+i);
    }
    return yearList;
}
/**
 * Method to setYearList
 * @param yearList
 */
public void setYearList(Map<String, String> yearList) {
    this.yearList = yearList;
}

/**
 * Ajax Method is called when the month value is selected , 
 * based on the selected month the days are populated.
 */
public void loadDays(){
    this.dayList = new TreeMap<String, String>();
    Calendar cal = Calendar.getInstance();
    int yyyy = (this.inputYear!=null && this.inputYear.trim().length()>0 )?Integer.parseInt(this.inputYear):cal.get(Calendar.YEAR);
    String selDate = this.inputDay;
    String selMonth = this.inputMonth;
    int lastDay = 1;
    if(yyyy%4==0 && selMonth!=null && selMonth.equals("02")){
        lastDay = 29;
    }else if(selMonth!=null && selMonth.equals("02")){
        lastDay = 28;
    }else if(selMonth!=null && ((selMonth.equals("01") || selMonth.equals("03") || selMonth.equals("05") || selMonth.equals("07") || selMonth.equals("08") || selMonth.equals("10") || selMonth.equals("12")))) {
        lastDay = 31;
    }else{
        lastDay = 30;
    }
    for(int i=1; i<=lastDay;i++){
        String days = i<=9?"0"+i:""+i;
        this.dayList.put(days, days);
    }

    if(selDate!=null && selDate.trim().length()>0 && Integer.parseInt(selDate)<=lastDay){
        this.inputDay = selDate;
    }
}
/**
 * Method to get the Input day.
 * @return inputDay
 */
public String getInputDay() {
    return inputDay;
}
/**
 * Method to set the Input Day.
 * @param inputDay
 */
public void setInputDay(String inputDay) {
    this.inputDay = inputDay;
}
/**
 * Method to get the Input year.
 * @return inputYear
 */
public String getInputYear() {
    return inputYear;
}
/**
 * Method to set the Input year.
 * @param inputYear
 */
public void setInputYear(String inputYear) {
    this.inputYear = inputYear;
}
/**
 * Method to getInputMonth 
 * @return inputMonth
 */
public String getInputMonth() {
    return inputMonth;
}
/**
 * Method to setInputMonth 
 * @param inputMonth
 */
public void setInputMonth(String inputMonth) {
    this.inputMonth = inputMonth;
}
公共类DateUtils{
私人地图月刊;
私人地图日清单;
私人地图年鉴;
私有字符串inputYear=“”;
私有字符串inputMonth=“”;
私有字符串inputDay=“”;
/**
*方法来获取月份列表。
*@return monthList
*/
公共地图getMonthList(){
this.monthList=newtreemap();
//this.monthList=newhashmap();
对于(inti=1;i0)?Integer.parseInt(this.inputYear):cal.get(Calendar.YEAR);
字符串selDate=this.inputDay;
字符串selMonth=this.inputMonth;
int lastDay=1;
如果(yyyy%4==0&&selmount!=null&&selmount.equals(“02”)){
最后一天=29;
}else如果(selmount!=null&&selmount.equals(“02”)){
最后一天=28;
}如果(selmount!=null&((selmount.equals(“01”)| selmount.equals(“03”)| selmount.equals(“05”)| selmount.equals(“07”)| selmount.equals(“08”)| selmount.equals(“10”)| selmount.equals(“12”)){
最后一天=31;
}否则{
最后一天=30;
}

对于(int i=1;i您有两种可能性:

  • 使用属性“立即”

    使用immediate=“true”可以跳过流程验证阶段

  • 使用属性“进程”

    使用process=“@this”时,您不会使用ajax请求处理整个表单,而只处理此字段


  • 尝试使用这两个属性,但仍然不成功,是否有其他方法可以做到这一点。