2016-02-25 60 views
0

這是問題: 我們有包含包含xhtml表單的主頁。 commandButton調用動作,但有限範圍的bean不會按inputText的值填充。下面的代碼:包含在ui中的表單:包括不填充的bean

welcome_file.xhtml

<h:head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <title>XHTML Page</title> 
    <h:outputStylesheet name="CSS/style.css" />  
    </h:head> 
    <h:body> 
     <f:facet name="last"> 
     <link rel="stylesheet" type="text/css" href="#{facesContext.externalContext.requestContextPath}/resources/CSS/style.css" /> 
     <h:outputStylesheet name="CSS/style.css" /> 
     </f:facet> 
    <f:view contentType="text/html" id="fview"> 
     <p:layout fullPage="true" resizeTitle="resize"> 
      <p:layoutUnit position="north" size="68" id="north" style="font-size: 100%; text-align: center;" header="КРАУДСОРСИНГОВАЯ ПЛАТФОРМА MEPHORCE"> 
      <h:outputText value="#{clientBean.clientFIO.get(0)} #{clientBean.clientFIO.get(1)} #{clientBean.clientFIO.get(2)}" style="font-size: 100%; text-align: left;"/>  
      </p:layoutUnit> 
         <p:layoutUnit position="west" id="west" resizable="false" header="Меню" style="height:580px;overflow:hidden;" size="225"> 
      <h:panelGroup id="menu" layout="block"> 

     <h:form> 
     <f:ajax render=":content"> 
      <ul> 
       <li><h:commandLink value="Профиль" action="#{beanClient.setPage('profile')}" /></li>    
       <li><h:commandLink value="Мои проекты" action="#{beanClient.setPage('my_projects')}" /></li>    
       <li><h:commandLink value="Новый проект" action="#{beanClient.setPage('new_project')}" /></li> 
       <li><h:commandLink value="Чат с модератором" action="#{beanClient.setPage('mod_chat')}" /></li> 
       <li><h:commandLink value="Сообщество" action="#{beanClient.setPage('community')}" /></li> 
       <li><h:commandLink value="Выход" action="#{clientBean.logout()}" /></li> 
      </ul> 
     </f:ajax> 
    </h:form> 
     </h:panelGroup> 
      </p:layoutUnit> 
<p:layoutUnit styleClass="layoutUnitCenter" position="center"> 
    <h:panelGroup id="content" layout="block"> 
    <ui:include src="/WEB-INF/includes/client/#{beanClient.page}.xhtml" /> 
    </h:panelGroup> 
    </p:layoutUnit> 

     <p:layoutUnit position="east" size="0" style="width:0px; display:none;" id="east"> 
     </p:layoutUnit> 

     <p:layoutUnit position="south" resizable="true" id="south"> 

     </p:layoutUnit> 
    </p:layout> 

</f:view> 
</h:body> 

new_project.xhtml

<table width="100%" height="100%" > 
    <h:form id="form"> 
     <p:growl id="growl" class="ui-growl" showDetail="false" sticky="false" life="10000"/> 
    <tr> 
     <td> 
    <h:panelGrid columns="2" styleClass="h_pgrid-style" > 

    <h:outputLabel for="title" value="Название: " styleClass="el-style"/> 
    <p:inputText id="title" size="45" required="true" value="#{projectBean.prTitle}" >      
    </p:inputText> 

    </h:panelGrid></td> 

     <td> 
     <h:panelGrid columns="2" styleClass="h_pgrid-style" > 


    <f:facet name="footer">  
     <h:panelGroup style="display:block; text-align:center"> 
      <p:commandButton id="submit" type="submit" value="Создать" process="@this" action="#{projectBean.CreateNewProjectSubmit(clientBean.clientId)}" 
          update="growl" ajax="true"/> 
     </h:panelGroup> 
    </f:facet>   

    </h:panelGrid> 

    </td>   

    </tr> 
    </h:form>  
    </table> 

項目bean類

import java.io.Serializable; 
import java.sql.*; 
import java.util.*; 
import javax.faces.application.FacesMessage; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped; 
import javax.faces.bean.ViewScoped; 
import javax.faces.component.UIComponent; 
import javax.faces.context.FacesContext; 
import javax.persistence.PrePersist; 
import org.primefaces.component.inputtext.InputText; 
import trg.dao.ProjectsDAOImpl; 


@ManagedBean 
@SessionScoped 

public class ProjectBean 
{ 
    private List<Project> projectList; 

    private int prId; 
    private String prTitle; 
    private String prDesctiption; 
    private java.util.Date prDate; 
    private int prBudget; 
    private String prStatus; 
    private int prMod; 

    public int getPrId() 
    { 
     return prId; 
    } 

    public void setPrId(int prId) 
    { 
     this.prId=prId; 
    } 

    public String getPrTitle() { 
     System.out.println ("GetPrTitle:"+prTitle); 
     return prTitle; 
    } 

    public void setPrTitle(String prTitle) { 
     this.prTitle = prTitle; 
     System.out.println ("SetPrTitle:"+prTitle); 
    } 

    public String getPrDesctiption() { 
     return prDesctiption; 
    } 

    public void setPrDesctiption(String prDesctiption) { 
     this.prDesctiption = prDesctiption; 
    } 

    public java.util.Date getPrDate() { 
     return prDate; 
    } 

    public void setPrDate(java.util.Date prDate) { 
     this.prDate = prDate; 
    } 

    public int getPrBudget() { 
     return prBudget; 
    } 

    public void setPrBudget(int prBudget) { 
     this.prBudget = prBudget; 
    } 

    public String getPrStatus() { 
     return prStatus; 
    } 

    public void setPrStatus(String prStatus) { 
     this.prStatus = prStatus; 
    } 

    public int getPrMod() { 
     return prMod; 
    } 

    public void setPrMod(int prMod) { 
     this.prMod = prMod; 
    } 


    public List<Project> getProjectList(int cl_id) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException 
    { 
     ProjectsDAOImpl projectsDAOImpl = new ProjectsDAOImpl(); 

     projectList = projectsDAOImpl.getProjectListClient(cl_id); 
     return projectList; 

    } 

     public void CreateNewProjectSubmit(int cl_id) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException 
    { 

     FacesContext context=FacesContext.getCurrentInstance(); 

     /*ProjectsDAOImpl projectsDAOImpl = new ProjectsDAOImpl(); 
     projectsDAOImpl.createNewProject(prTitle, prDesctiption, prDate, prBudget, prStatus, prMod, cl_id); 
*/ 
     FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Проект успешно создан",""); 
     context.addMessage(null, message);  

    } 

clientBean.java

import java.sql.SQLException; 
import java.util.ArrayList; 
import java.util.List; 
import javax.faces.application.FacesMessage; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped; 
import javax.faces.context.FacesContext; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpSession; 
import trg.dao.ClientDAOImpl; 
import trg.service.SessionBean; 

@ManagedBean 
@SessionScoped 
public class ClientBean { 
    private int clientId; 
    private String clFam; 
    private String clFirst; 
    private String clSec; 
    private String clPass; 

    public int getClientId() { 
     return clientId; 
    } 

    public void setClientId(int clientId) { 
     this.clientId = clientId; 
    } 

    public String getClFam() { 
     return clFam; 
    } 

    public void setClFam(String clFam) { 
     this.clFam = clFam; 
    } 


    public String getClFirst() { 
     return clFirst; 
    } 

    public void setClFirst(String clFirst) { 
     this.clFirst = clFirst; 
    }  

    public String getClSec() { 
     return clSec; 
    } 

    public void setClSec(String clSec) { 
     this.clSec = clSec; 
    }  

public String getClPass() { 
     return clPass; 
    } 

    public void setClPass(String clPass) { 
     this.clPass = clPass; 
    }    


public List<Client> getClientsList() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException 
    { 
     ClientDAOImpl clientDAOImpl = new ClientDAOImpl(); 

     List<Client> clientlist = clientDAOImpl.getClientList(); 

     return clientlist; 

    } 

public List<String> getClientFIO() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException 
    { 
     ClientDAOImpl clientDAOImpl = new ClientDAOImpl(); 

     List<Client> clientFIO = clientDAOImpl.getFio(clientId); 

     List<String> clientFIO_separated=new <String>ArrayList(); 

     clientFIO_separated.add(clientFIO.get(0).getClFamily()); 
     clientFIO_separated.add(clientFIO.get(0).getClFirstName()); 
     clientFIO_separated.add(clientFIO.get(0).getClSecName()); 

     return clientFIO_separated; 

    } 

public String ClAuthSubmit() 
      throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException 
    { 

    ClientDAOImpl clientDAOImpl = new ClientDAOImpl(); 

    FacesContext context=FacesContext.getCurrentInstance(); 

     boolean valid= clientDAOImpl.rightClient(clientId, clPass);; 
     if (valid) { 
       HttpSession session = SessionBean.getSession(); 
       session.setMaxInactiveInterval(15*60); 
       return("success_ClientAuth"); 
     }  
      else{ 

      FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Вы ввели неверные данные",""); 
      context.addMessage(null, message); 
      return(null); 
     } 

     } 
public String logout() { 
    FacesContext context=FacesContext.getCurrentInstance(); 
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); 
    HttpSession session = request.getSession(false); 
     session.setAttribute("userlogged","0"); 
     session.setAttribute("ID", clientId); 

     return "loggedout"; 
    } 
} 
+0

嗨,BalusC。問題出在Project bean中,setters不能通過點擊commandbutton來調用。 –

回答

0

您正在使用clientBeanbeanClient,哪一個是正確的?我相信這會導致您的JSF頁面感到困惑,並可能啓動兩個不同的bean(或者至少拋出一些未渲染的異常),從而導致頁面控制/數據問題。

+0

嗨。 beanClient只包含一些用戶角色「Client」註銷的方法,而clientBean是模型bean。由projectBean引發的問題 - 項目模型。 –

+0

您可能想嘗試在getter中爲您希望顯示在屏幕上的文本設置調試斷點,以查看頁面是否要求此值。 – radekbaranowski