I am trying to use Richfaces suggestion box. Based on the value selected from the suggestionbox, I am trying to change outputtext value next to it.
Here is my xhtml code:
<td align="left">
<h:inputText onchange="submit();" immediate="true" id="productname" valueChangeListener="#{salesBean.updateProductRate}" autocomplete="false"/>
</td>
<td align="left">
<h:outputText id="rate" binding="#{salesBean.productRate}"/>
</td>
<rich:suggestionbox width="290" suggestionAction="#{salesBean.suggest}" var="state" for="productname">
<f:facet name="nothingLabel">
<h:outputText value="No Products found" />
</f:facet>
<f:facet name="header">
<h:outputText value="Select Product" />
</f:facet>
<h:column>
<h:outputText value="#{state.name}"/>
</h:column>
</rich:suggestionbox>
When I type 'a' in the inputtext (for example) Richfaces suggestionbox shows the list of names starting with letter 'a'. If I select one of the names (say 'asd'), only 'a' which I typed earlier gets submitted in the form.
How to make the whole name 'asd' to get submitted in the form? Please help
Thanks in advance
(I am using JSF 1.2 along with Richfaces 3.3.2)
Updated Code
<td align="left">
<h:inputText immediate="true" id="productname" autocomplete="false">
</h:inputText>
</td>
<td align="left">
<h:outputText id="rate" binding="#{salesBean.productRate}"/>
</td>
<rich:suggestionbox width="290"
suggestionAction="#{salesBean.suggest}" var="state" for="productname">
<f:facet name="nothingLabel">
<h:outputText value="No Products found" />
</f:facet>
<f:facet name="header">
<h:outputText value="Select Product" />
</f:facet>
<h:column>
<h:outputText value="#{state.name}"/>
</h:column>
<a4j:support event="onselect" action="#{salesBean.updateProductRate}" reRender="rate">
<f:setPropertyActionListener value="#{state.name}" target="#{salesBean.selectedProductName}" />
</a4j:support>
This is my java code
HtmlOutputText productRate = new HtmlOutputText();
public String updateProductRate()
{
System.out.println("Successfully entered ");
SalesDAO dao = new SalesDAO();
//getProductRate().setValue(dao.fetchRateForProductEntered(evt.getNewValue().toString()));
//selectedProductName = dao.fetchRateForProductEntered(evt.getNewValue().toString());
return "success";
}
public HtmlOutputText getProductRate() {
return productRate;
}
public void setProductRate(HtmlOutputText productRate) {
this.productRate = productRate;
}
public List<ProductSuggestOBJ> suggest(Object input)
{
SalesDAO dao = new SalesDAO();
List<ProductSuggestOBJ> suggestionList = new ArrayList<ProductSuggestOBJ>();
String userInput = (String)input;
if(!userInput.trim().equalsIgnoreCase(""))
{
suggestionList = dao.suggestProductFromDatabase(userInput);
}
return suggestionList;
}
private String selectedProductName;
public String getSelectedProductName() {
return selectedProductName;
}
public void setSelectedProductName(String sel开发者_开发问答ectedProductName) {
this.selectedProductName = selectedProductName;
}
The same error remains. Plz help.
It seems that you want to select a product from the suggestion box and then call the #{salesBean.updateProductRate}
to calculate the product rate for the selected product.
You can do it by directly attaching an onselect
event to the suggestion box using a4j:support
instead of using the valueChangeListener
of the h:inputText
that the suggestion box provides value to.
<h:inputText immediate="true" id="productname" />
<br/>
<h:outputText id="rate" value="#{salesBean.productRate}"/>
<rich:suggestionbox width="290" suggestionAction="#{salesBean.suggest}" var="state" for="productname">
<f:facet name="nothingLabel">
<h:outputText value="No Products found" />
</f:facet>
<f:facet name="header">
<h:outputText value="Select Product" />
</f:facet>
<h:column>
<h:outputText value="#{state.name}"/>
</h:column>
<a4j:support event="onselect" action="#{salesBean.updateProductRate}" reRender="rate">
<f:setPropertyActionListener value="#{state.name}" target "#{salesBean.selectedProductName}" />
</a4j:support>
</rich:suggestionbox>
In the salesBean
, add the selectedProductName
properties and its getter and setter. In the updateProductRate()
, you use the selectedProductName
to calculate the product rate and assign the result to the productRate
精彩评论