我正在尝试使用 JSF 设置一个数据表,其中包含行总数框,该框将汇总行中任何框的行总数 onChange。该行看起来像:
<tr id="input_row_1">
<td id="mondayInput1">
<h:inputText id="monday1" size="4" value="#{timesheet.monday1}" required="false" />
<!-- <input name="monday1" class="smallInput" type="number" size="2" maxlength="4" min="0"/> -->
</td>
<td id="tuesdayInput1">
<h:inputText id="tuesday1" size="4" value="#{timesheet.tuesday1}" required="false" />
<!--<input name="tuesday1" class="smallInput" type="number" size="2" maxlength="4" min="0"/> -->
</td>
<td id="wednesdayInput1">
<h:inputText id="wednesday1" size="4" value="#{timesheet.wednesday1}" required="false" />
<!--<input name="wednesday1" class="smallInput" type="number" size="2" maxlength="4" min="0"/> -->
</td>
<td id="thursdayInput1">
<h:inputText id="thursday1" size="4" value="#{timesheet.thursday1}" required="false" />
<!--<input name="thursday1" class="smallInput" type="number" size="2" maxlength="4" min="0"/> -->
</td>
<td id="fridayInput1">
<h:inputText id="friday1" size="4" value="#{timesheet.friday1}" required="false" />
<!--<input name="friday1" class="smallInput" type="number" size="2" maxlength="4" min="0"/> -->
</td>
<td id="saturdayInput1">
<h:inputText id="saturday1" size="4" value="#{timesheet.saturday1}" required="false" />
<!--<input name="saturday1" class="smallInput" type="number" size="2" maxlength="4" min="0"/> -->
</td>
<td id="sundayInput1">
<h:inputText id="sunday1" size="4" value="#{timesheet.sunday1}" required="false" />
<!--<input name="sunday1" class="smallInput" type="number" size="2" maxlength="4" min="0"/> -->
</td>
<td>
<h:inputText id="total1" size="4" value="#{timesheet.total1}" required="false" />
<!-- <input name="total1" id="total1" type="text" size="5" readonly="readonly" /> -->
</td>
所以我首先尝试添加onChange="#{timesheet.setTotal1}"
到 day 条目,但 onChange 事件调用 javascript,而不是 java / JSF 代码。有人可以帮助更新总数吗?
编辑:我已经接受了 BalusC 的回答,但还需要event
在标签中包含属性以<f:ajax>
使其正常工作,就像这样
<h:inputText id="friday1" size="4" value="#{timesheet.friday1}" maxlength="4" required="false" >
<f:ajax event="change" render="total1" listener="#{timesheet.updateTotal1}" />
</h:inputText>