Reputation: 612
I have a problem with the display of what I want. Basically I have a dropdown list and on change of what is inside the dropdown list I want some input of the page that fill in on it own. Here is one of the input I want to fill in. I call the listener on a ajax method. XHTML Code :
<h:outputText value="Version" styleClass="section-label"/>
<h:inputText id="version" value="#{contextSchemeDetailBean.contextScheme.schemeVersionId}"
required="true" maxlength="45"
requiredMessage="Please fill out 'Version' field."
label="Version" styleClass="section-content input-section">
<f:validateLength maximum="45"/>
<p:ajax listener="#{codeListBaseBean.onSelectCodeList}"/>
</h:inputText>
The Java code allow me to get the good value of what to fill in those input(GetBlablaFromblabla).
JavaBean Code :
public void onSelectCodeList(SelectEvent event){
setSelectedCodeListName(event.getObject().toString());
System.out.println("Element selectionne :" + event.getObject());
System.out.println("Agency Id correspondant :" + GetAgencyIdFromCodeListName(event.getObject().toString()));
System.out.println("Version correspondante :" + GetVersionFromCodeListName(event.getObject().toString()));
//System.out.println("agency id ="+agencyIdListValueRepository.findOne(GetAgencyIdFromCodeListName(event.getObject().toString())).getAgencyIdListValueId());
//System.out.println("agency id ===="+getAgencyIdListValues());
//setAgencyIdListValue(agencyIdListValueRepository.findOne(GetAgencyIdFromCodeListName(event.getObject().toString())));
System.out.println("=======================================");
}
Now what i want to do is to put those value inside my input on each change of the value selected in my dropdown list. I know it must not be hard but i m not familiar with jsf. Thanks !
My droplist is coded like that :
<h:outputText value="Code List" styleClass="section-label"/>
<p:autoComplete id="inputCodeList"
requiredMessage="Please fill out 'Code List' field."
styleClass="section-content input-section"
completeMethod="#{codeListBean.completeInput}"
dropdown="true" scrollHeight="220"
itemValue="#{codeListBaseBean.codeList.listId}">
<p:ajax event="itemSelect" listener="#{codeListBaseBean.onSelectCodeList}"/>
</p:autoComplete>
-S
Upvotes: 3
Views: 4234
Reputation: 441
You need the ajax tag inside your dropdown, and use render
to update the value of the input text field.
<h:form id="myForm">
<h:selectOneMenu value="#{bean.selectedVal}">
<f:selectItems value="#{bean.someValues}"/>
<f:ajax listener="#{bean.selectValueChanged}" render="myForm:inputToBeUpdated"/>
</h:selectOneMenu>
<h:inputText id="inputToBeUpdated" value="#{bean.inputTextVal}"/>
</h:form>
Bean
String selectedVal;
String inputTextVal;
void selectValueChanged() {
//set value of the input text
inputTextVal = "some value";
}
Upvotes: 2