2016-09-08 10 views
-1

私はJavaで新しいので、今学ぶことを試みています。 私は手動で追加されたデータテーブルのデータを更新する必要がありますaddInventoryメソッド、魔女は途中で動作しています。 「編集」ボタンがありますが、機能していません。ここでエラーがある:編集可能なp:データテーブル

javax.el.ELException: org.springframework.dao.InvalidDataAccessApiUsageException: Bean object must not be null; nested exception is java.lang.IllegalArgumentException: Bean object must not be null 
    at org.apache.el.parser.AstValue.invoke(AstValue.java:260) ~[tomcat-embed-el-8.0.32.jar!/:8.0.32] 
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267) ~[tomcat-embed-el-8.0.32.jar!/:8.0.32] 
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149) ~[javax.faces-2.2.11.jar!/:2.2.11] 
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88) ~[javax.faces-2.2.11.jar!/:2.2.11] 
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813) ~[javax.faces-2.2.11.jar!/:2.2.11] 
    at javax.faces.component.UICommand.broadcast(UICommand.java:300) ~[javax.faces-2.2.11.jar!/:2.2.11] 
    at javax.faces.component.UIData.broadcast(UIData.java:1108) ~[javax.faces-2.2.11.jar!/:2.2.11] 
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790) ~[javax.faces-2.2.11.jar!/:2.2.11] 
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282) ~[javax.faces-2.2.11.jar!/:2.2.11] 
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) ~[javax.faces-2.2.11.jar!/:2.2.11] 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [javax.faces-2.2.11.jar!/:2.2.11] 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) [javax.faces-2.2.11.jar!/:2.2.11] 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:654) [javax.faces-2.2.11.jar!/:2.2.11] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) [tomcat-embed-core-8.0.32.jar!/:8.0.32] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [tomcat-embed-core-8.0.32.jar!/:8.0.32] 
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.0.32.jar!/:8.0.32] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [tomcat-embed-core-8.0.32.jar!/:8.0.32] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [tomcat-embed-core-8.0.32.jar!/:8.0.32]. 

サービスコードは次のとおりです。

@Service 
public class InventoryService implements IInventoryService{ 

    @Autowired 
    private InventoryDao inventoryDAO; 

List<InventoryDTO> inventoryDTOs = new ArrayList<InventoryDTO>(); 

@Override 
public List<Inventory> getInventories() { 
    return (List<Inventory>) inventoryDAO.findAll(); 
} 


public Inventory getInventories(long id) { 
    return inventoryDAO.findOne(id); 
} 

public Inventory getInventory(long id) { 
    Inventory inventory = inventoryDAO.findOne(id); 
    if (inventory == null) 
     return null; 

    return inventory.convertToDTO().convertToEntity(); 
} 

@Override 
public Inventory addInventory(Inventory inventory) { 
    return inventoryDAO.save(inventory); 
} 

@Override 
public Inventory updateInventory(Inventory inventory) { 
    return inventoryDAO.save(inventory); 
} 

これは、コントローラのビューである:私はあなたに1つの方法を提案

@Component("invController") 
@Scope(FacesViewScope.NAME) 
@Getter 
@Setter 
public class InvController implements Serializable { 
private static final long serialVersionUID = 1L; 

private boolean canEdit; 

private List<Inventory> inventories = new ArrayList<>(); 

@Autowired 
private InventoryService inventoryService; 
private InventoryDTO inventoryDTO = new InventoryDTO(); 

@PostConstruct 
public void initInventories() { 
    inventories = inventoryService.getInventories(); 
} 

public void setInventoryDTO(InventoryDTO inventoryDTO) { 
    this.inventoryDTO = inventoryDTO; 
} 

public void addInventory() { 
    if (!inventories.add(inventoryService.addInventory(inventoryDTO.convertToEntity()))) 
     throw new IllegalArgumentException("Inventory could not be added to DB!"); 
} 

public void updateInventory() { 
    Inventory inventory = inventoryService.getInventory(inventoryDTO.convertToEntity().getId()); 
    inventoryService.updateInventory(inventory).convertToDTO(); 
    inventoryDTO = new InventoryDTO(); 
} 

Here is the xhtml file: 

<html> 

<h:head> 

    <!-- For Bootstrap responsive grid --> 
    <link rel="stylesheet" 
     href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" /> 

</h:head> 

<ui:define name="content"> 
    <h:form id="form" style="height:725px"> 
     <center> 
      <h3 class="hardblue" style="margin-top:50px">Inventar</h3> 
     </center> 
     <center> 

      <p:tabView scrollable="true" style="width:75%; margin-top:100px"> 
       <p:tab title="Beneficiar"> 
        <p:panelGrid style="width:500px" id="idPanel1" var="beneficiaries" 
           editable="true" editMode="row"> 


         <p:column headerText="Numar">Numar 
          <h:inputText value="#{invController.inventoryDTO.number}" 
             disabled="#{!invController.canEdit}" 
             style="font-weight:bold" /> 

         </p:column> 
         <p:column headerText="Descriere">Descriere 
          <h:inputText value="#{invController.inventoryDTO.description}" 
             disabled="#{!invController.canEdit}" 
             style="font-weight:bold" /> 
         </p:column> 
         <p:column headerText="Tipul de explozibil">Tip de explozibil 
          <h:inputText value="#{invController.inventoryDTO.types}" 
             disabled="#{!invController.canEdit}" 
             style="font-weight:bold" /> 
         </p:column> 
        </p:panelGrid> 

       </p:tab> 
       <p:tab title="Locul de unde se ridica"> 
        <p:dataTable> 
         <p:column headerText="Loc"> 
          <h:outputText value="#{tableComplete.locRidicare}" /> 
         </p:column> 
         <p:column headerText="Localitate"> 
          <h:outputText value="#{tableComplete.locRidicareLoc}" /> 
         </p:column> 
        </p:dataTable> 
       </p:tab>. 
      <p:tab title="Locul unde se transporta"> 
        <p:dataTable> 
         <p:column headerText="Loc"> 
          <h:outputText value="#{tableComplete.locDepunere}" /> 
         </p:column> 
         <p:column headerText="Localitate"> 
          <h:outputText value="#{tableComplete.locDepunereLoc}" /> 
         </p:column> 
        </p:dataTable> 
       </p:tab> 
       <p:tab title="Vehicul Transport Marfa"> 
        <p:dataTable> 
         <p:column headerText="Marca"> 
          <h:outputText value="#{tableComplete.vehTrMarfaMarca}" /> 
         </p:column> 
         <p:column headerText="Model"> 
          <h:outputText value="#{tableComplete.vehTrMarfaModel}" /> 
         </p:column> 
         <p:column headerText="Nr. Inmatriculare"> 
          <h:outputText value="#{tableComplete.vehTrMarfaNI}" /> 
         </p:column> 
         <p:column headerText="Numele Conducatorului"> 
          <h:outputText value="#{tableComplete.vehTrMarfaC}" /> 
         </p:column> 
         <p:column headerText="Act de Identitate al Conducatorului"> 
          <h:outputText value="#{tableComplete.vehTrMarfaAIC}" /> 
         </p:column> 
        </p:dataTable> 
       </p:tab> 
       <p:tab title="Vehicul Transport Paza"> 
        <p:dataTable> 
         <p:column headerText="Marca"> 
          <h:outputText value="#{tableComplete.vehTrPazaMarca}" /> 
         </p:column> 
         <p:column headerText="Model"> 
          <h:outputText value="#{tableComplete.vehTrPazaModel}" /> 
         </p:column> 
         <p:column headerText="Nr. Inmatriculare"> 
          <h:outputText value="#{tableComplete.vehTrPazaNI}" /> 
         </p:column> 
         <p:column headerText="Numele Conducatorului"> 
          <h:outputText value="#{tableComplete.vehTrPazaC}" /> 
         </p:column> 
         <p:column headerText="Act de Identitate al Conducatorului"> 
          <h:outputText value="#{tableComplete.vehTrPazaAIC}" /> 
         </p:column> 
        </p:dataTable> 
       </p:tab> 
       <p:tab title="Artificier"> 
        <p:panelGrid style="width:500px" id="idPanel2" var="pyrotechnists" 
           editable="true" editMode="row"> 
         <p:column headerText="numar">Numar 
          <h:inputText value="#{invController.inventoryDTO.number}" 
             disabled="#{invController.canEdit}" 
             style="font-weight:bold" /> 
         </p:column> 
         <p:column headerText="Descriere">Descriere 
          <h:inputText value="#{invController.inventoryDTO.description}" 
             disabled="#{invController.canEdit}" 
             style="font-weight:bold" /> 
         </p:column> 
         <p:column headerText="Act de Identitate">Act de identitate 
          <h:inputText value="#{invController.inventoryDTO.types}" 
             disabled="#{invController.canEdit}" 
             style="font-weight:bold" /> 
         </p:column> 
        </p:panelGrid> 

        <p:commandButton value="Add Inventory" id="ajax" update="@form" actionListener="#{invController.addInventory}" styleClass="ui-priority-primary" /> 

       </p:tab> 
       <p:tab title="Paza 1"> 
        <p:dataTable> 
         <p:column headerText="Nume"> 
          <h:outputText value="#{tableComplete.paza1Nume}" /> 
         </p:column> 
         <p:column headerText="Prenume"> 
          <h:outputText value="#{tableComplete.paza1Prenume}" /> 
         </p:column> 
         <p:column headerText="Act de Identitate"> 
          <h:outputText value="#{tableComplete.paza1AI}" /> 
         </p:column> 
        </p:dataTable> 
       </p:tab> 
       <p:tab title="Paza 2"> 
        <p:dataTable> 
         <p:column headerText="Nume"> 
          <h:outputText value="#{tableComplete.paza2Nume}" /> 
         </p:column> 
         <p:column headerText="Prenume"> 
          <h:outputText value="#{tableComplete.paza2Prenume}" /> 
         </p:column> 
         <p:column headerText="Act de Identitate"> 
          <h:outputText value="#{tableComplete.paza2AI}" /> 
         </p:column> 
        </p:dataTable> 
       </p:tab> 
       <p:tab title="Tipuri de Materii Explozive"> 
        <p:dataTable> 
         <p:column headerText="Nr. N.U."> 
          <h:outputText value="#{tableComplete.tipENr}" /> 
         </p:column> 
         <p:column headerText="C.I. Diviziune"> 
          <h:outputText value="#{tableComplete.tipEDiv}" /> 
         </p:column> 
         <p:column headerText="Denumire Comerciala"> 
          <h:outputText value="#{tableComplete.tipEDC}" /> 
         </p:column> 
         <p:column headerText="Marcaj C.E."> 
          <h:outputText value="#{tableComplete.tipEMarcaj}" /> 
         </p:column> 
         <p:column headerText="Furnizor"> 
          <h:outputText value="#{tableComplete.tipEFurnizor}" /> 
         </p:column> 
         <p:column headerText="Cantitate"> 
          <h:outputText value="#{tableComplete.tipECant}" /> 
         </p:column> 
        </p:dataTable> 
       </p:tab> 
      </p:tabView> 



     <p:dataTable paginator="true" scrollable="true" id="invList" value="#{invController.inventories}" ajax="true" var="inv" style="width:75%; margin-top:50px"> 
     <p:column> 
      <f:facet name="header"> 
       <h:outputText value="Number" /> 
      </f:facet> 
      <h:outputText value="#{inv.number}" /> 
     </p:column> 
     <p:column> 
      <f:facet name="header"> 
       <h:outputText value="Cui" /> 
      </f:facet> 
     </p:column> 
     <p:column> 
      <f:facet name="header"> 
       <h:outputText value="Tipuri" /> 
      </f:facet> 
      <h:outputText value="#{inv.types}" /> 
     </p:column> 
     <p:column> 
     <f:facet name="header"> 
      <h:outputText value="Edit" /> 
     </f:facet> 
      <p:commandButton value="Edit" id="ajax2" update="invList" actionListener="#{invController.updateInventory()}" styleClass="ui-priority-primary" /> 
     </p:column> 
     </p:dataTable> 
     </center> 
    </h:form> 
</ui:define> 
    </html> 
</ui:composition> 
+0

なぜあなたはこのspring-mvcにタグを付けましたかプライムフェイスではありませんか? – Kukeltje

+0

申し訳ありませんが、私はこれを知っていたと言いました。私はそれを修正した! –

+0

[ask]と[mcve]とhttp://www.stackoverflow.com/tags/jsf/infoを読んで質問を改善してください。これは、コメントノイズを減らす – Kukeltje

答えて

0


これは、<h:inputText value="#{bean.value}" rendered="#{bean.flag}"/>と書いてあります。フラグvariableは、beanの次に<h:outputText>でfalseです。
次に、テーブル内のこのテキストをクリックするjqueryを書きます。このフラグはtrueに変更され、h:outputTextはfalseフラグで表示されます。

+0

すぐに答えてくれてありがとう、しかし私はJAVAメソッドを使用してそれを作る必要があります。私は問題が何であるか把握できません。私の意見では、問題は方法ですが、私は理由を知らないのです。編集ボタンはそこにありますが、私がそれを押すと、投稿されたエラーがスローされます。 –

+0

このコマンドを試すことができます: '' – Numb

+0

まだ動作しません。今私はEDITボタンを押したときにエラーはありませんが、アクションはありません....フィールドはまだ出力テキストであり、編集可能ではありません。 –

関連する問題