如何在JSF中将String解析为java.util.Date?

时间:2014-03-26 12:16:16

标签: java jsf primefaces

这是我的时间和时间详细信息inTimeFirst,outTimeFirst,inTimeSecond,outTimeShift是数据库中的时间数据类型,总小时数是double(10,2)类型。但在实体类中它是Date类型。 这是我的表格

          

    <p:selectOneMenu value="#{attendanceController.attendanceApp.attendance.empId}">
                <f:selectItems value="#{employeeController.empapp.itemsAvailableSelectOne}" var="comp" itemLabel="#{comp.empNumber}" itemValue="#{comp.empId}" />
                <f:converter converterId="employeeconvert" /> 
            </p:selectOneMenu>       
      </p:column>
      <p:column headerText="Mark Attendance">
          <h:outputLabel value="Attendance:" for="attendance" />   
          <h:selectOneMenu id="attendance" valueChangeListener="#{attendanceController.attendanceApp.valuChangeHandler}" onchange="submit()" immediate="true">
        <f:selectItem itemValue=" " itemLabel="--select--" />
        <f:selectItem itemValue="P" itemLabel="P"/>
         <f:selectItem itemValue="L" itemLabel="L"/>
          <f:selectItem itemValue="HL" itemLabel="HL"/>
    </h:selectOneMenu>  
          <h:outputLabel value="Leave Type:" for="attendance" />    
      <h:selectOneMenu disabled="#{!attendanceController.attendanceApp.visible}" value="#{attendanceController.attendanceApp.attendance.leaveId}">
       <f:selectItems value="#{leavecont.leaveapp.itemsAvailableSelectOne}" var="leav" itemLabel="#{leav.leaveName}" itemValue="#{leav.leaveId}"/>
       <f:converter converterId="leavesconverter" />
   </h:selectOneMenu>
      </p:column>

      <p:column headerText="In Time">

          <p:inputText value="#{attendanceController.attendanceApp.attendance.inTimeFirst}" size="5" maxlength="5"/>
      </p:column>

      <p:column headerText="Out Time">

          <p:inputText value="#{attendanceController.attendanceApp.attendance.outTimeFirst}" size="5" maxlength="5"/>
      </p:column>

       <p:column headerText="In Time">

          <p:inputText value="#{attendanceController.attendanceApp.attendance.inTimeSecond}" size="5" maxlength="5"/>
      </p:column>

      <p:column headerText="Out Time">

          <p:inputText value="#{attendanceController.attendanceApp.attendance.outTimeShift}" size="5" maxlength="5"/>
      </p:column>

       <p:column headerText="Total Hours">

          <p:inputText value="#{attendanceController.attendanceApp.attendance.totalHours}" size="5" maxlength="5">
              <h:commandButton value="Calculate"  action="#{attendanceController.attendanceApp.calculateTotalHours()}" style="font: 15px"  />
          </p:inputText>
      </p:column>
        </p:dataTable

这是我从命令按钮调用的方法,当我输入intime,outtime并按下计算按钮时,我会调用名称计算按钮我应该得到总时数这是我的计算方法,我正在调用

public String calculateTotalHours(){
   long firstShiftseconds = attendance.getOutTimeFirst().getTime()-attendance.getInTimeFirst().getTime();
     long secondShiftseconds = attendance.getOutTimeShift().getTime()-attendance.getInTimeSecond().getTime();
  double totalhours=(double)(firstShiftseconds+secondShiftseconds)/1000*60*60;
  JSFUtil.addSuccessMessage(" "+totalhours);
  attendance.setTotalHours(totalhours);
 return "Employee_attendance";
}

无法将类型类java.lang.String的9:00转换为类java.util.Date错误导致

0 个答案:

没有答案