Я хочу создать очень простой JSF веб-страницы, которые я хотел бы использовать для расчета цен:значения Вычислить по значению вставки
<h:form>
<h:outputText value="Number of Computers"/>
<h:panelGroup layout="block" id="desktopClients_select" style="padding-top: 3px;" styleClass="text">
<h:inputText id="desktopClients" value="#{pricingCalculator.computers}">
<f:ajax event="change" render="@form" listener="#{pricingCalculator.calculateTotalPrice}"/>
</h:inputText>
</h:panelGroup>
<h:outputText value="Email support incidents"/>
<h:panelGroup layout="block" id="email_support_incidents" style="padding-top: 3px;" styleClass="text">
<h:inputText id="email_support_incidents_text" value="#{pricingCalculator.emailSupportIncidents}">
<f:ajax event="change" render="@form" listener="#{pricingCalculator.calculateTotalPrice}"/>
</h:inputText>
</h:panelGroup>
<h:outputText value="Phone support incidents"/>
<h:panelGroup layout="block" id="phone_support_incidents" style="padding-top: 3px;" styleClass="text">
<h:inputText id="phone_support_incidents_text" value="#{pricingCalculator.phoneSupportIncidents}">
<f:validateLongRange minimum="1" maximum="150" />
<f:ajax event="change" render="@form" listener="#{pricingCalculator.calculateTotalPrice}"/>
</h:inputText>
</h:panelGroup>
<h:outputText value="Total price"/>
<h:panelGroup layout="block" id="total_price" style="padding-top: 3px;" styleClass="text">
<h:outputText value="#{pricingCalculator.calculateTotalPrice}"/>
</h:panelGroup>
</h:panelGrid>
</h:form>
Bean:
@Named
@ViewScoped
public class PricingCalculator implements Serializable
{
private int computers;
private float emailSupportIncidents;
private float phoneSupportIncidents;
private float totalPrice;
// Prices for each component and service
private final float computers_price = 299;
private final float emailSupportIncidents_price = 300;
private final float phoneSupportIncidents_price = 150;
public String getCalculateTotalPrice()
{
totalPrice = (computers_price * computers)
+ (emailSupportIncidents_price * emailSupportIncidents)
+ (phoneSupportIncidents_price * phoneSupportIncidents);
String result = Float.toString(totalPrice);
return result;
}
public int getComputers()
{
return computers;
}
public void setComputers(int computers)
{
this.computers = computers;
}
public float getEmailSupportIncidents()
{
return emailSupportIncidents;
}
public void setEmailSupportIncidents(float emailSupportIncidents)
{
this.emailSupportIncidents = emailSupportIncidents;
}
public float getPhoneSupportIncidents()
{
return phoneSupportIncidents;
}
public void setPhoneSupportIncidents(float phoneSupportIncidents)
{
this.phoneSupportIncidents = phoneSupportIncidents;
}
public float getTotalPrice()
{
return totalPrice;
}
public void setTotalPrice(float totalPrice)
{
this.totalPrice = totalPrice;
}
}
Когда я ввожу какое-то значение в поля ввода я хотел бы пересчитать общую цену. У меня сейчас два вопроса: я получаю исключение serverError: class javax.el.MethodNotFoundException /pricing_calculator.xhtml @115,136 listener="#{pricingCalculator.calculateTotalPrice}": Method not found: [email protected](javax.faces.event.AjaxBehaviorEvent)
и когда я вставляю новое значение, предыдущее значение равно нулю. Его не помнят должным образом.
Какая часть именно за исключением не понимаешь? В нем говорится, что он ожидал найти в упомянутом выше методе сообщение, но у вас действительно нет такого. – BalusC