2016-06-29 2 views
0

SelectOneMenu에서 선택한 값을 변경 한 후 outputLabel을 업데이트하는 메소드를 호출하려고합니다. 나는 이미 여기에 답변 된 모든 질문을 시도했지만 작동하지 않습니다. 내 Managed Bean의 메소드가 호출되지 않고 콘솔에서 인쇄하려고 시도했지만 작동하지 않습니다. 예외는 없습니다. 나는이 대답Ajax가 selectOneMenu에서 Managed Bean의 메소드를 호출하지 않습니다. valueChanged item

commandButton/commandLink/ajax action/listener method not invoked or input value not updated

을 발견했지만 내가 뭔가를 누락하는 경우 아마도 이미이 질문에 대해 모든 따르기는 하겠지만 점을 확인했습니다 모른다.

내 SelectOneMenu 코드는

<h:selectOneMenu id="creditos" value="#{comprarCreditoBean.quantidadeCreditos}" required="true" requiredMessage=" *Campo obrigatório!"> 

          <f:selectItem itemLabel="Selecione uma opção" noSelectionOption="true"/> 
          <f:selectItem itemValue="30" itemLabel="30 Créditos" /> 
          <f:selectItem itemValue="60" itemLabel="60 Créditos" /> 
          <f:selectItem itemValue="90" itemLabel="90 Créditos" /> 
          <f:selectItem itemValue="120" itemLabel="120 Créditos" /> 
          <f:ajax event="change" 
           execute="formulario" 
           render="valPagamento" 
           listener="#{comprarCreditoBean.tratarMudancaCreditos}"/> 

        </h:selectOneMenu> 
         <br /> 
        </h:panelGroup> 
        <h:message class="mensagens" for="creditos" /> 

        <h:outputLabel value="Total a Pagar: "/> 
        <h:outputLabel id="valPagamento" value="#{comprarCreditoBean.valorPagamento}" required="true" requiredMessage=" *Campo obrigatório!"> 
         <f:convertNumber currencySymbol="R$" type="currency"/> 
        </h:outputLabel> 

인 마스터 템플릿은 <h:head>을 사용하고 selectOneMenu는 <h:form> 구성 요소 내부에 이미 있습니다. 내 ManagedBean은 다음의 방법에

가 호출해야합니다 방법이 아닌 경우

public void tratarMudancaCreditos(AjaxBehaviorEvent evento){ 

    System.out.println("Hi"); 
    System.out.println(this.quantidadeCreditos); 
    if(this.quantidadeCreditos == 30){ 
     this.valorPagamento = 1.0; 
    }else if(this.quantidadeCreditos == 60){ 
     this.valorPagamento = 2.0; 
    }else if(this.quantidadeCreditos == 90){ 
     this.valorPagamento = 3.0; 
    }else if(this.quantidadeCreditos == 120) { 
     this.valorPagamento = 4.0; 
    } 
} 

내가, 내 페이지에 업데이트해야 값을 업데이트하기 위해 노력하고있어 방법에 대해 정말 걱정 호출되는 동안, 그 안에있는 일은 아무것도 작동하지 않습니다.

내가 템플릿을 사용하고 EDIT1 @가

관련이 있다면 톰캣 8.0과 JSF 2.0을 사용하고, 그래서 내 템플릿에서 관련 코드를 게시하도록하겠습니다.

먼저 SelecteOneMenu가있는 페이지에서 다음 템플릿을 사용하여 템플릿을 사용하고 있는지 확인합니다. 같은 페이지에서

<ui:composition template="/Template.xhtml" 
xmlns:jsp="http://java.sun.com/JSP/Page" 
xmlns="http://www.w3.org/1999/xhtml" 
xmlns:b="http://bootsfaces.net/ui" 
xmlns:f="http://java.sun.com/jsf/core" 
xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:h="http://java.sun.com/jsf/html" version="2.0"> 

, 나는이 기본적으로 내 페이지에서 건설입니다

<ui:define name="corpo-da-pagina"> 
<div class="panel panel-default"> 
     <div class="panel-heading"> 
      <h3 class="panel-title"><span class="tituloPanel">Comprar Créditos</span></h3> 
     </div> 
     <div class="panel-body" align="center"> 
     <h:form id="formulario"> 
       <h:panelGrid columns="3"> 
        <h:outputLabel value="Quantidade de Créditos (1 Minuto = 1 crédito): "/> 
        <h:panelGroup> 
         <h:selectOneMenu id="creditos" value="#{comprarCreditoBean.quantidadeCreditos}" required="true" requiredMessage=" *Campo obrigatório!"> 
          <f:selectItem itemLabel="Selecione uma opção" noSelectionOption="true"/> 
          <f:selectItem itemValue="30" itemLabel="30 Créditos" /> 
          <f:selectItem itemValue="60" itemLabel="60 Créditos" /> 
          <f:selectItem itemValue="90" itemLabel="90 Créditos" /> 
          <f:selectItem itemValue="120" itemLabel="120 Créditos" /> 
          <f:ajax event="change" 
           execute="formulario" 
           render="valPagamento" 
           listener="#{comprarCreditoBean.tratarMudancaCreditos}"/> 
         </h:selectOneMenu> 
         <br /> 
        </h:panelGroup> 
        <h:message class="mensagens" for="creditos" /> 

        <h:outputLabel value="Total a Pagar: "/> 
        <h:outputLabel id="valPagamento" value="#{comprarCreditoBean.valorPagamento}" required="true" requiredMessage=" *Campo obrigatório!"> 
         <f:convertNumber currencySymbol="R$" type="currency"/> 
        </h:outputLabel> 
<h:commandButton class="btn btn-default" value="Comprar" action="#{comprarCreditoBean.efetuarCompra}"/> 
       <h:button class="btn btn-default" value="Voltar" outcome="paginaPrincipal"/>  
     </h:form> 

이 다른 일들이 잘됩니다.

내 template.xhtml이 코드에 정의 : 내가 흥미로운 점을 발견했습니다 2

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:b="http://bootsfaces.net/ui" 
    xmlns:h="http://java.sun.com/jsf/html" version="2.0"> 

<h:head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
    <meta name="viewport" content="width=device-width" /> 

    <!-- CSS --> 
    <link rel="stylesheet" type="text/css" href="resources/css/estilo.css" /> 
    <link rel="stylesheet" type="text/css" href="resources/css/bootstrap.min.css" /> 
    <link rel="stylesheet" type="text/css" href="resources/css/bootstrap.css" /> 

    <!-- JS --> 
    <script src="resources/js/jquery.js"></script> 
    <script src="resources/js/bootstrap.min.js"></script> 

    <!-- Ícone Navegador --> 
    <link href="resources/imagens/icone.png" rel="shortcut icon" type="image/x-icon" /> 

    <title>e-BlueCard</title> 
</h:head> 
<h:body> 
    <f:view> 
     <div id="header" align="center"> 
      <ui:include src="/menu.xhtml" /> 
     </div> 

     <ui:insert name="corpo-da-pagina">Conteúdo</ui:insert> 

     <div class="well well-sm" align="center"> 
      <div id="footer" align="center"> 
       <span id="rodape">2016. Análise e Desenvolvimento de Sistemas - e-blue Card. Todos os direitos reservados.</span> 
      </div> 
     </div> 
    </f:view> 
</h:body> 

@Edit. 내가 크롬 브라우저에서 엽니 다했는데, 나는 SelectOneMenu에서 값을 변경하려고 할 때 항상 콘솔을 볼 수있는 F12를 사용했습니다, 브라우저에서 콘솔은 다음과 같은 오류를 보여줍니다

Error caught by Chrome

+0

을 이해하는 데 도움이 될 수있는 링크입니다 나이 (템플릿을 사용하지 않고) 그것은 나를 위해 잘 작동했습니다. 템플릿과'h : form'을 어떻게 통합 시켰는가를 보여주는 최소한의 코드를 게시 할 수 있습니까? – tfosra

+0

@tfosra 템플릿 코드를 게시하고 구성 요소가 내 페이지에서 사용되는 방식을 게시하여 내 질문에 대한 판을 만들었습니다. –

답변

0

당신 form` 하나의 페이지 내부 : 여기이

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://xmlns.jcp.org/jsf/core" 
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets" 
    OTHER LIBRARIES HERE 
    > 

    <h:head> 
     HEADER CONTENT HERE 
    </h:head> 
    <h:body> 
     BODY CONTENT HERE 
    </h:body> 
</html> 

처럼 <html ...></html>와 템플릿에 <jsp:root ...>를 교체해야하면 나는 단순한 '시간과 코드를 테스트 한 JSF templates

+0

템플릿 코드를 변경해 보았지만 여전히 outputLabel에서 업데이트가 작동하지 않았습니다. 새 템플릿 코드는 으로 시작하고으로 끝납니다. 모든 JSP 태그와 라이브러리 삽입을 제거했습니다. 도움을 주셔서 감사합니다! –

+0

서버 로그에 예외가 있습니까? – tfosra

+0

아니요, 불행히도 예외는 없습니다. 페이지가 잘로드되고, 모든 유효성 검증 메시지가 잘됩니다. 유일한 문제는 outputLabel의 값입니다. 이 값을 업데이트 할 수 없으면 패턴 값을 사용하여 데이터베이스의 삽입이 제대로 실행되고 있습니다. –

관련 문제