我正在爲用戶填寫一份調查問卷,其中一項要求是實施用戶回答問題時填寫的進度欄。檢查ValueListBoxes是否在GWT中得到應答
我不能完全包裹我的頭的錯誤是與列表框。如果我選擇一個值,計數器上升很好,但如果我選擇另一個值,計數器會再次增加,當它保持相同的值時。
基本下面的例子:
- 選擇值
- TRUE
- FALSE
完成百分比:0%(默認下拉列表與 「選擇值」作爲默認值)
- TRUE
- 選擇值
- FALSE
完成百分比:2%
- FALSE
- 選擇值
- TRUE
完成百分比:4%(應爲2%,因爲這個問題已經有了答案)
這是改變處理程序的代碼:
final ValueChangeHandler<Boolean> booleanChangeHandler = new ValueChangeHandler<Boolean>()
{
@Override
public void onValueChange(final ValueChangeEvent<Boolean> event)
{
Boolean value = event.getValue();
changeAnsweredQuestionTotal(String.valueOf(value));
}
};
並且這改變了進度條。我也用它來檢查文本框是否填寫完畢。
public void changeAnsweredQuestionTotal(String value)
{
//Window.alert(value);
boolean isEmpty = (value == null) || value.equalsIgnoreCase("Null") ? true : value.isEmpty();
Integer answered;
Integer totalQuestions;
String text = this.getQuestionsAnswered().getText().substring(0, 2);
text= text.replaceAll("\\s+", "");
answered = text.isEmpty() ? 0 : Integer.valueOf(text);
answered = (answered < 0) ? 0 : answered;
totalQuestions = this.getTotalQuestions().getValue().isEmpty() ? 0 : Integer.valueOf(this.getTotalQuestions().getValue());
String result;
if (isEmpty)
{
answered = answered - 1;
answered = (answered < 0) ? 0 : answered;
result = answered + " questions answered. ";
}
else
{
if (!value.equalsIgnoreCase("null"))
{
answered = answered > totalQuestions ? totalQuestions : answered + 1;
}
result = answered + " questions answered. ";
}
Integer percent = (answered*100)/totalQuestions;
percent = (percent > 100) ? 100 : percent;
}
任何幫助將不勝感激。