Olá!
Estou com um problema ao validar 2 campos em uma pagina.
A validação é comparar se a hora inicial é menor que a hora final.Caso não seja, eu retorno uma mensagem na tela ao clicar no botao submit.Ele diz que o metodo não existe, mas o metodo jah esta criado no bean.
O erro é esse, que aparece no message do formulario:
/alocaturma.jsp(93,2) '#{bAloca.verificaHora}' Method not found: br.unig.scif.bean.AlocaBean@1055f4d.verificaHora(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
meu jsp:
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c1"%><%@taglib
uri="http://richfaces.org/rich" prefix="rich"%><%@taglib
uri="http://richfaces.org/a4j" prefix="a4j"%><%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Alocação de turmas nas salas</title>
</head>
<body>
<f:view>
<h:form>
<center><h3>Alocação das turmas nas salas</h3></center>
<h:outputText value="Campus:" />
<h:selectOneMenu id="campus" style="width: 114px" value="#{bAloca.codcampus}">
<f:selectItems value="#{bCampus.listarCampus}"/>
</h:selectOneMenu>
<br>
<h:outputText value="Turma:"/>
<h:selectOneMenu id="turma" style="width: 125px" value="#{bAloca.codturma}">
<f:selectItems value="#{bCampus.listarTurmas}"/>
</h:selectOneMenu>
<br>
<h:outputText value="Hora inicial:"/>
<h:selectOneMenu id="horainicio" style="width: 47px" value="#{bAloca.horainicio}">
<f:selectItem itemLabel="00" itemValue="00"/>
<f:selectItem itemLabel="01" itemValue="01"/>
<f:selectItem itemLabel="02" itemValue="02"/>
<f:selectItem itemLabel="03" itemValue="03"/>
<f:selectItem itemLabel="04" itemValue="04"/>
<f:selectItem itemLabel="05" itemValue="05"/>
<f:selectItem itemLabel="06" itemValue="06"/>
<f:selectItem itemLabel="07" itemValue="07"/>
<f:selectItem itemLabel="08" itemValue="08"/>
<f:selectItem itemLabel="09" itemValue="09"/>
<f:selectItem itemLabel="10" itemValue="10"/>
<f:selectItem itemLabel="11" itemValue="11"/>
<f:selectItem itemLabel="12" itemValue="12"/>
<f:selectItem itemLabel="13" itemValue="13"/>
<f:selectItem itemLabel="14" itemValue="14"/>
<f:selectItem itemLabel="15" itemValue="15"/>
<f:selectItem itemLabel="16" itemValue="16"/>
<f:selectItem itemLabel="17" itemValue="17"/>
<f:selectItem itemLabel="18" itemValue="18"/>
<f:selectItem itemLabel="19" itemValue="19"/>
<f:selectItem itemLabel="20" itemValue="20"/>
<f:selectItem itemLabel="21" itemValue="21"/>
<f:selectItem itemLabel="22" itemValue="22"/>
<f:selectItem itemLabel="23" itemValue="23"/>
</h:selectOneMenu>
:
<h:selectOneMenu id="minutoinicio" style="width: 47px" value="#{bAloca.minutoinicio}">
<f:selectItem itemLabel="00" itemValue="00"/>
<f:selectItem itemLabel="10" itemValue="10"/>
<f:selectItem itemLabel="20" itemValue="20"/>
<f:selectItem itemLabel="30" itemValue="30"/>
<f:selectItem itemLabel="40" itemValue="40"/>
<f:selectItem itemLabel="50" itemValue="50"/>
</h:selectOneMenu>
<br>
<h:outputText value="Hora fim:"/>
<h:selectOneMenu id="horafim" style="width: 47px" value="#{bAloca.horafim}">
<f:selectItem itemLabel="00" itemValue="00"/>
<f:selectItem itemLabel="01" itemValue="01"/>
<f:selectItem itemLabel="02" itemValue="02"/>
<f:selectItem itemLabel="03" itemValue="03"/>
<f:selectItem itemLabel="04" itemValue="04"/>
<f:selectItem itemLabel="05" itemValue="05"/>
<f:selectItem itemLabel="06" itemValue="06"/>
<f:selectItem itemLabel="07" itemValue="07"/>
<f:selectItem itemLabel="08" itemValue="08"/>
<f:selectItem itemLabel="09" itemValue="09"/>
<f:selectItem itemLabel="10" itemValue="10"/>
<f:selectItem itemLabel="11" itemValue="11"/>
<f:selectItem itemLabel="12" itemValue="12"/>
<f:selectItem itemLabel="13" itemValue="13"/>
<f:selectItem itemLabel="14" itemValue="14"/>
<f:selectItem itemLabel="15" itemValue="15"/>
<f:selectItem itemLabel="16" itemValue="16"/>
<f:selectItem itemLabel="17" itemValue="17"/>
<f:selectItem itemLabel="18" itemValue="18"/>
<f:selectItem itemLabel="19" itemValue="19"/>
<f:selectItem itemLabel="20" itemValue="20"/>
<f:selectItem itemLabel="21" itemValue="21"/>
<f:selectItem itemLabel="22" itemValue="22"/>
<f:selectItem itemLabel="23" itemValue="23"/>
</h:selectOneMenu>
:
<h:selectOneMenu id="minutofim" style="width: 47px" value="#{bAloca.minutofim}" validator="#{bAloca.verificaHora}" required="true">//aqui chamo a validação
<f:selectItem itemLabel="00" itemValue="00"/>
<f:selectItem itemLabel="10" itemValue="10"/>
<f:selectItem itemLabel="20" itemValue="20"/>
<f:selectItem itemLabel="30" itemValue="30"/>
<f:selectItem itemLabel="40" itemValue="40"/>
<f:selectItem itemLabel="50" itemValue="50"/>
</h:selectOneMenu>
<h:message for="minutofim" id="msgverificahora"></h:message>//esse é o message q utilizo para retornar a mensagem
<br>
<h:outputText value="Dia da semana:"/>
<h:selectOneMenu id="diasemana" style="width: 157px" value="#{bAloca.diasemana}">
<f:selectItem itemLabel="SEGUNDA" itemValue="SEGUNDA"/>
<f:selectItem itemLabel="TERCA" itemValue="TERCA"/>
<f:selectItem itemLabel="QUARTA" itemValue="QUARTA"/>
<f:selectItem itemLabel="QUINTA" itemValue="QUINTA"/>
<f:selectItem itemLabel="SEXTA" itemValue="SEXTA"/>
<f:selectItem itemLabel="SABADO" itemValue="SABADO"/>
</h:selectOneMenu>
<br>
<h:outputText value="Quantidade:"/>
<h:inputText value="#{bAloca.quantidade}"/>
<br>
<h:commandButton value="mostrar" actionListener="#{bAloca.salasdisponiveis}"/><br><br>
<a4j:keepAlive beanName="bAloca"/>
<rich:dataTable border="1" id="salas" value="#{bAloca.listaSalaDisponivel}" var="salas">
<h:column id="descricao">
<h:outputText value="#{salas.dscSala}"></h:outputText>
<f:facet name="header">
<h:outputText value="descricao"></h:outputText>
</f:facet>
</h:column>
<h:column id="capacidade">
<h:outputText value="#{salas.capacidade}"></h:outputText>
<f:facet name="header">
<h:outputText value="capacidade"></h:outputText>
</f:facet>
</h:column>
<h:column id="arcondicionado">
<h:outputText value="#{salas.arCondicionado}"></h:outputText>
<f:facet name="header">
<h:outputText value="Ar condicionado"></h:outputText>
</f:facet>
</h:column>
<h:column id="ventilador">
<h:outputText value="#{salas.ventilador}"></h:outputText>
<f:facet name="header">
<h:outputText value="ventilador"></h:outputText>
</f:facet>
</h:column>
<h:column id="tipoquadro">
<h:outputText value="#{salas.tipoQuadro}"></h:outputText>
<f:facet name="header">
<h:outputText value="Tipo do Quadro"></h:outputText>
</f:facet>
</h:column>
<h:column id="salvar">
<f:facet name="header">
<h:outputText value="Salvar"></h:outputText>
</f:facet>
<h:commandLink action="#{bAloca.confirmaAlocaForm}" actionListener="#{bAloca.confirmaAloca}">
<h:outputText value="Salvar"></h:outputText>
<f:param id="codsala" value="#{salas.id.codSala}"/>
<f:param id="codcampus" value="#{salas.id.codCampus}"/>
<f:param id="codbloco" value="#{salas.id.codBloco}"/>
<f:param id="codpavimento" value="#{salas.id.codPavimento}"/>
</h:commandLink>
</h:column>
</rich:dataTable>
</h:form>
</f:view>
</body>
</html>
meu metodo no bean:
public void verificaHora(FacesContext context,UIComponent toValidate,ActionEvent event) {System.out.println("entrou");
UIParameter parametroHoraInicio = (UIParameter) event.getComponent().findComponent("horainicio");
String horaini = parametroHoraInicio.getValue().toString();
UIParameter parametroMinutoInicio = (UIParameter) event.getComponent().findComponent("minutoinicio");
String minutoini = parametroMinutoInicio.getValue().toString();
horainicio = horaini + ":" + minutoini;
UIParameter parametroHoraFim = (UIParameter) event.getComponent().findComponent("horafim");
String horaf = parametroHoraFim.getValue().toString();
UIParameter parametroMinutoFim = (UIParameter) event.getComponent().findComponent("minutofim");
String minutof = parametroMinutoFim.getValue().toString();
horafim = horaf + ":" + minutof;
SimpleDateFormat formhora = new SimpleDateFormat("HHmmss");
long min_1 = getMinutos(horainicio, formhora);
long min_2 = getMinutos(horafim, formhora);
if (min_1 > min_2){
((UIInput)toValidate).setValid(false);
FacesMessage message = new FacesMessage("Horário inválido");
context.addMessage(toValidate.getClientId(context), message);
}
}
É a primeira vez que faço isso, se alguem puder me ajudar.
Grato!