2017-05-05 173 views
0

我試圖在頁面中創建一個命令按鈕,但沒有得到操作方法的響應。JSF Primefaces commandButton

PS:新中PrimeFaces

package br.com.copagaz.inova.mobile.web.mb.frota; 

import java.io.Serializable; 

import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped; 
import javax.faces.event.ActionEvent; 

@SessionScoped 
@ManagedBean(name = "CadFrota", eager = false) 
public class CadFrota implements Serializable { 

    private static final long serialVersionUID = -5734393292489385792L; 

    public void teste(ActionEvent actionEvent){ 
     System.out.println("teste: " + actionEvent.toString()); 
    } 
} 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"> 

    <h:body> 
     <ui:composition template="/pages/templates/master.xhtml"> 
      <ui:define name="divMain"> 

       <h:form id="frotaForm"> 

        <p:growl showDetail="false" life="3000" /> 


        <p:panel id="toggleable1" header="Frota" toggleable="false" closable="false" widgetVar="frotaPanel" 
          style="margin-bottom:20px"> 

         <p:panelGrid style="width:90%"> 

          <p:row> 
           <p:column> 
            <p:outputLabel>Filial:</p:outputLabel> 
           </p:column> 
           <p:column> 
            <p:inputText id="i10" value="" /> 
           </p:column> 
           <p:column> 
            <p:outputLabel>Veículo:</p:outputLabel> 
           </p:column> 
           <p:column> 
            <p:inputText id="i11" value="" /> 
           </p:column> 
           <p:column> 
            <p:outputLabel>Placa:</p:outputLabel> 
           </p:column> 
           <p:column colspan="3"> 
            <p:inputText id="i12" value="" /> 
           </p:column> 
           <p:column> 
            <p:outputLabel>Senha:</p:outputLabel> 
           </p:column> 
           <p:column colspan="3"> 
            <p:inputText id="i121" value="" /> 
           </p:column> 
          </p:row> 
          <p:row> 
           <p:column> 
            <p:outputLabel>Segmento:</p:outputLabel> 
           </p:column> 
           <p:column> 
            <p:selectOneMenu id="console" value="XXXXX" style="width:125px"> 
             <f:selectItem itemLabel="Select One" itemValue="" /> 
             <f:selectItem itemLabel="AAA" itemValue="AAA" /> 
             <f:selectItem itemLabel="BBB" itemValue="BBB" /> 
             <f:selectItem itemLabel="CCC" itemValue="CCC" /> 
            </p:selectOneMenu> 
           </p:column> 
           <p:column > 
            <h:panelGrid columns="2"> 
             <h:outputText value="Massico: " /> 
             <p:selectBooleanCheckbox value="" /> 
            </h:panelGrid> 
           </p:column> 
           <p:column > 
            <h:panelGrid columns="2"> 
             <h:outputText value="Ativo: " /> 
             <p:selectBooleanCheckbox value="" /> 
            </h:panelGrid> 
           </p:column> 
           <p:column colspan="2"> 
           </p:column> 

          </p:row> 
         </p:panelGrid> 
        </p:panel> 

        <p:separator style="width:90%;height:5px;border: none;" /> 

        <p:panelGrid columns="2" styleClass="panelgridCmdBtn"> 
         <p:commandButton id="gravaFrota" value="Gravar" action="#{CadFrota.teste}" icon="ui-icon-bullet"/> 
         <p:commandButton id="gravarCheckFilial" value="Gravar Check Filial" actionListener="#{Viagem.gravarCheckFilial}" ajax="false" style="margin-left:1px" /> 
         <p:commandButton value="Voltar" immediate="true" style="margin-left:3px" /> 
        </p:panelGrid> 

       </h:form> 

      </ui:define> 
     </ui:composition> 
    </h:body> 
</html> 

錯誤堆棧:

引起:javax.el.PropertyNotWritableException:/pages/controle/cadastro_frota.xhtml @ 25,42 value =「」:設置操作的非法語法
引起b Y:javax.el.PropertyNotWritableException:非法語法設定操作

回答

1

inputText值不能爲空

<p:inputText id="i10" value="" /> 

相反,你必須與一定財產託管bean實例:

<p:inputText id="i10" value="#{cadFrota.attribute}" /> 

注意

您必須在ManagedBean中創建屬性。


看看在Primeface show cases,約inputText

+0

我認爲它這個,這是一個註冊頁面,所以我有這個值來接收來自用戶輸入的數據? – AgamenonD2

+0

是的,這是正確的@ AgamenonD2 –

+1

tks,解決了這個問題。 – AgamenonD2