2012-08-02 2 views
5

JSF로 데이터 테이블을 설정하려고합니다. 행에있는 모든 상자의 행 전체를 합계하는 행 합계 상자가 있습니다. onChange의 JSF 액션

<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}"을 추가하려고하지만 OnChange 이벤트는 자바 스크립트가 아닌 자바/JSF 코드를 호출과 같은 행이 보인다. 누군가가 전체 업데이트를 도울 수 있습니까?

이 편집 : 나는 BalusC의 답변을 수용하지만, 필요 또한 실제로 그렇게

<h:inputText id="friday1" size="4" value="#{timesheet.friday1}" maxlength="4" required="false" > 
    <f:ajax event="change" render="total1" listener="#{timesheet.updateTotal1}" /> 
</h:inputText> 

답변

6

같은 일을 얻을 수있는 <f:ajax> 태그에 event 속성을 포함 할 수있다는 onchange 속성이 단지 일반으로 처리됩니다 텍스트 핸들러 함수를 나타내는 HTML 속성. 이것은 "일반 바닐라"HTML과 다르지 않습니다. 그 속성에있는 EL 표현식은 단지 값 표현식으로 취급됩니다. tag documentation도 참조하십시오.

질문 기록을 기반으로 JSF 2.x를 사용하고 있습니다. JSF 2.x를 사용하고 있습니다. (JSF 2.x에서 JSF 1.x와 다르게 많은 일이 다뤄지므로 앞으로의 질문에서 정확한 JSF impl/version을 명시하십시오) . 따라서 새로운 JSF 2.0 <f:ajax> 태그를 사용하면됩니다.

public void changeTotal1(AjaxBehaviorEvent event) { 
    total1 = ...; 
} 
+0

<h:inputText ...> <f:ajax listener="#{timesheet.changeTotal1}" render="idOfTotalComponent" /> </h:inputText> ... <h:outputText id="idOfTotalComponent" value="#{timesheet.total1}" /> 

나는 이런 짓을하고 지금은 무엇입니까 : "javax.servlet.ServletException : 부동산의 'updateTotal1'형 com.timesheet.Timesheet을 찾을 수 없습니다"updateTotal1이 재산 인 것처럼 메소드/액션이 아닌 –

+0

''에서 의미하는 것은 무엇입니까? 분명히'f :'taglib의 XML 네임 스페이스는 전혀 선언되지 않았다. ' '태그 전체는 실제로 "일반 텍스트"로 취급됩니다 (읽기 : EL은 값 표현식으로 처리됩니다). – BalusC

+0

그러나 선언되었습니다. html 코드 –