gpt4 book ai didi

java - h 的值 :inputText is null in ManagedBean

转载 作者:行者123 更新时间:2023-11-29 03:36:22 24 4
gpt4 key购买 nike

我在 JSF 中有以下代码

<h:outputLabel value="Date" for="rdate" />
<h:inputText id="rdate" autocomplete="off"
value="#{myMB.abstractProject.joinedDate}">
</h:inputText>

在实体类中,我声明为

private Date joinedDate; 

public Date getJoinedDate() {
return joinedDate;
}

public void setJoinedDate(Date joinedDate) {
this.joinedDate= joinedDate;
}

问题是,在 ManagedBean 中,我得到以下的 null

System.out.println("date in save method "
+ abstractRequest.getJoinedDate());

这可能是什么原因? h:inputText事实上在<h:form> .我的 bean 的范围是 @ViewAccessScoped

最佳答案

您需要使用 f:convertDateTime .喜欢:

<h:outputLabel value="Date" for="rdate" />
<h:inputText id="rdate" autocomplete="off" value="#{myMB.abstractProject.joinedDate}" label="Date">
<f:convertDateTime pattern="dd-MM-yyyy" />
</h:inputText>

Here是一个例子。

编辑:

这是我所做的:

xhtml:

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" template="/WEB-INF/templates/globalTemplate.xhtml">

<ui:define name="title">1532116</ui:define>
<ui:define name="content">
<h:form>
<h:outputLabel value="Date" for="date" />
<h:inputText id="date" value="#{so15321163.date}" label="Date" required="true">
<f:convertDateTime pattern="dd-MM-yyyy"/>
</h:inputText>
<h:message for="date" style="color:red" />
<h:commandButton value="Submit" actionListener="#{so15321163.listener}"/>
</h:form>
</ui:define>
</ui:composition>

托管 bean:

package app.so.dev.web.controller;

import java.io.Serializable;
import java.util.Date;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;

@ManagedBean(name="so15321163")
@ViewScoped // @SessionScoped
public class SO15321163 implements Serializable {

/**
*
*/
private static final long serialVersionUID = 8012804893825661900L;
private Date date;

@PostConstruct
public void init() {

}

public void listener(ActionEvent event) {
System.out.println(date);
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}
}

关于java - h 的值 :inputText is null in ManagedBean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15321163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com