form included with ui:include not filling bean

396 views Asked by At

This is problem: we have main page with included xhtml containing form. commandButton invoke action, but scoped bean doesn't fills by value of inputText. Code below:

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> 

project bean class

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";
     }
}
1

There are 1 answers

2
radekbaranowski On

You are using clientBean and beanClient, which one is correct ? I believe that this causes your JSF page to get confused and to possibly initiate two different beans (or at least throw some unrendered exception)., in consequence causing page control/data issues.