我有 JSF 页面。我的目标是通过从数据库中获取模式来动态构建验证器。
我下面的代码不起作用。我的意思是正则表达式失败。
<p:inputText value="#{basvuruBean.basvuru.sistem.tavsiyeEdilenID}"
requiredMessage="Lütfen Tavsiye Edilen ID giriniz"
validatorMessage="#{basvuruBean.basvuru.sistem.tavsiyeEdilenIDHataMesaji}"
rendered="#{basvuruBean.basvuru.sistem.tavsiyeEdilenIDRendered}">
<f:validateRegex pattern="#{basvuruBean.basvuru.sistem.tavsiyeEdilenIDRegEX}" />
</p:inputText>
但这按预期工作
<p:inputText value="#{basvuruBean.basvuru.sistem.tavsiyeEdilenID}"
requiredMessage="Lütfen Tavsiye Edilen ID giriniz"
validatorMessage="#{basvuruBean.basvuru.sistem.tavsiyeEdilenIDHataMesaji}"
rendered="#{basvuruBean.basvuru.sistem.tavsiyeEdilenIDRendered}">
<f:validateRegex pattern="\d" />
</p:inputText>
basvuruBean.basvuru.sistem.tavsiyeEdilenIDRegEX
等于\d
。我通过在 JSF 页面上打印它来检查它。
我必须做什么才能使其工作?
支持bean的相关部分
import java.io.IOException;
import com.itextpdf.text.DocumentException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.FlowEvent;
@ManagedBean
@ViewScoped
public class BasvuruBean implements Serializable {
private Basvuru basvuru = new Basvuru();
private Sistem sistem;
private static final long serialVersionUID = 1L;
private String url;
private List<Sistem> sistemler = new ArrayList<Sistem>();
private SistemDAO sistemDAO = new SistemDAO();
@PostConstruct
void initialiseSession() {
FacesContext.getCurrentInstance().getExternalContext().getSession(true);
sistem=sistemler.get(0);
}
public BasvuruBean() {
sistemler = sistemDAO.tumSistemler();
this.basvuru.setSistem(sistem);
this.basvuru.setSirketAdi("Şirket Adı");
this.basvuru.setePosta("posta@sirket.com");
}
public void sistemChangeListener() {
System.out.println(sistem.getSistemAdi());
sistem.setKapsamaYaricapi(this.sistem.getKapsamaYaricapiDefault());
this.sistem.setKapsamaYuksekligi(this.sistem.getKapsamaYuksekligiDefault());
this.sistem.setFrekansMax(this.sistem.getFrekansMaxDefault());
this.sistem.setFrekansMin(this.sistem.getFrekansMinDefault());
this.sistem.setTavsiyeEdilenID(this.sistem.getTavsiyeEdilenIDDefault());
this.sistem.setRunway(this.sistem.getRunwayDefault());
this.sistem.setTrueRadiationDirection(this.sistem.getTrueRadiationDirectionDefault());
this.sistem.setApproachCAT(this.sistem.getApproachCATDefault());
this.sistem.setAntenVericiGucuDefault(this.sistem.getAntenVericiGucuDefault());
this.sistem.setAntenYuksekligiAGL(this.sistem.getAntenYuksekligiAGLDefault());
this.sistem.setFrekans(this.sistem.getFrekansDefault());
}
}
和 selectonemenu 改变系统对象
<p:selectOneMenu value="#{basvuruBean.basvuru.sistem}" converter="sistemConverter">
<f:selectItems value="#{basvuruBean.sistemler}" var="s" itemLabel="#{s.sistemAdi}" itemValue="#{s}" />
<p:ajax listener="#{basvuruBean.sistemChangeListener}" update="p2 genelbilgi" />
</p:selectOneMenu>