Question

I have a h:inputText with valueChangeListener, when the user type some code another h:inputText display data from MySQL about that code, the valueChangeListener works but the second h:inputText not displayed the value and only do it when I set the readonly attribute or I change the component to h:outputText

my facelets page is:

<h:form id="idFacturacion">  
<rich:panel>
<f:facet name="header">
<h:outputText value="FACTURACION AL CLIENTE" />
</f:facet>
<h:panelGrid columns="4">
<h:outputText value="Cedula: " />
<h:inputText value="#{facturaBean.encFactura.cedula}" onchange="submit();" valueChangeListener="#{facturaBean.processValueChange}" />
<h:outputText value="Nombre: " />
<h:inputText value="#{facturaBean.encFactura.nombre_cli}" />
</h:panelGrid>
</rich:panel>
</h:form>

facturaBean is:

@ManagedBean
@SessionScoped
public class FacturaBean {
    private EncFactura encFactura = new EncFactura();
    //getter and setter
    public void processValueChange(ValueChangeEvent event){
        String ced = event.getNewValue().toString();
        try{
            //do the database thing
            if(resultSet.next()){
                encFactura.setNombre_cli(resultSet.getString("nombre_cli"));
            }else{
                encFactura.setNombre_cli("");
            }
        }catch(SQLException error){
            facesContext.addMessage(null, new FacesMessage("Hubo un error SQL."));
        }
    }
}
Was it helpful?

Solution

Please see

May I suggest using ajax? Here is a primefaces example but you could apply to richfaces..

 <h:inputText value="#{facturaBean.stringOne}" >    
<p:ajax event="change" listener="#{facturaBean.processValueChange}" update="strTwo"/> </h:inputText> <h:outputText value="Nombre: " /> 
    <h:inputText id="strTwo" value="#{facturaBean.stringTwo}" /> 
</h:panelGrid>

private String stringOne= "";
private String stringTwo= "";


public void processValueChange(){
    stringTwo = stringOne;
}

With getters etc.. basically on change, fires off to ajax, you do your database call etc, then it returns the response and updates your other input field, it's a much cleaner way than trying to submit forms etc..

Also are you sure you want session scope?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top