我有一个带有 selectOneMenu 的表单,其中有两个选项和一个 inputText,如果用户选择第二个选项,则必须禁用它。我认为我应该使用 ajax 来更新 inputText,这就是我所做的,但不起作用。这是我的代码,请帮助我。谢谢
<h:outputText value="Modalita"></h:outputText>
<p:selectOneMenu value="#{vociCostoBean.selected.modalita}" immediate="true">
<f:selectItem itemLabel="Importo" itemValue="0"/>
<f:selectItem itemLabel="Quantita" itemValue="1"/>
<p:ajax update="uc" />
</p:selectOneMenu>
<h:outputText value="Costo Unitario"></h:outputText>
<p:inputText id="uc" disabled="#{vociCostoBean.selected.modalita !='1'}" value="#{vociCostoBean.selected.CUnitario}" />
<br></br>
还有这个 vociCostoBean:
@ManagedBean
@SessionScoped
public class VociCostoBean {
@EJB
private CostoBeanRemote cust;
private List<VociCosto> list;
private VociCosto selected= new VociCosto();
private boolean UcDisabled=true;
@PostConstruct
public void init(){
setList(new ArrayList<VociCosto>());
setList(cust.getAll());
//selected.setModalita("0");
}
public String newCosto(){
return "editCosto";
}
public void onRowSelect(){
FacesContext fc = FacesContext.getCurrentInstance();
System.out.println("|||||"+ getSelected().getNome());
try {
fc.getExternalContext().redirect("editCosto.jsf");
} catch (IOException e) {
}
}
public VociCosto getSelected() {
return selected;
}
public void setSelected(VociCosto selected) {
this.selected = selected;
}
public void setCust(CostoBeanRemote cust) {
this.cust = cust;
}
public List<VociCosto> getList() {
return list;
}
public void setList(List<VociCosto> list) {
this.list = list;
}
public boolean isUcDisabled() {
return UcDisabled;
}
public void setUcDisabled(boolean ucDisabled) {
this.UcDisabled = ucDisabled;
}
}
这是 VociCosto.java
package it.bway.timerep.entities;
import java.io.Serializable;
import javax.persistence.*;
import java.util.Set;
/**
* The persistent class for the VOCI_COSTO database table.
*
*/
@Entity
@Table(name="VOCI_COSTO")
public class VociCosto implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ID_COSTO", unique=true, nullable=false)
private int idCosto;
@Column(name="C_UNITARIO")
private int cUnitario;
@Column(length=1)
private String modalita;
@Column(length=50)
private String nome;
//bi-directional many-to-one association to NoteSpese
@OneToMany(mappedBy="vociCosto", fetch=FetchType.EAGER)
private Set<NoteSpese> noteSpeses;
public VociCosto() {
}
public int getIdCosto() {
return this.idCosto;
}
public void setIdCosto(int idCosto) {
this.idCosto = idCosto;
}
public int getCUnitario() {
return this.cUnitario;
}
public void setCUnitario(int cUnitario) {
this.cUnitario = cUnitario;
}
public String getModalita() {
return this.modalita;
}
public void setModalita(String modalita) {
this.modalita = modalita;
}
public String getNome() {
return this.nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public Set<NoteSpese> getNoteSpeses() {
return this.noteSpeses;
}
public void setNoteSpeses(Set<NoteSpese> noteSpeses) {
this.noteSpeses = noteSpeses;
}
@Override
public boolean equals(Object obj) {
try{
VociCosto toCompare = (VociCosto) obj;
if (idCosto==toCompare.getIdCosto()) return true;
return false;
} catch (Exception e){
return false;
}
}
@Override
public int hashCode(){
return idCosto;
}
}