Click here to Skip to main content
15,885,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all ,
i have a xhtml file that include a table that the user can change ( personally changes ).
the page build by ui:repeat from java bean class that include an array List .
when the user change the table ( the array list ) only the last array index is changing .

the XHTML file :
XML
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core" 
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css"/>
    <h:head>
        <title>Web TIme :  A simple example Title</title>
        <meta http-equiv="refresh" content="60"/>
    </h:head>
    <h:body>
        <div class="w3-container w3-light-grey w3-border">
        <p>Today : #{webTimeBean.time}</p>
        <p>Hello : #{userBean.email}</p>
        </div>    
            <table class="w3-table w3-bordered w3-striped">
       <tr>
            <th>Game #</th>
            <th>Home Team</th>
            <th>Away Team</th>
            <th>Home Score </th>
            <th>Away Score</th>
            <th>Bet</th>
      </tr>
                <ui:repeat var="elem" value="#{userBean.matchList}"  varStatus="status" >
        <tr>
            <h:form>
             <td>
                 <h:outputText value="#{elem.matchNumber}"  />
            </td>
            <td>
                <h:outputText value="#{elem.homeTeam}" />
            </td>
            <td>
                <h:outputText value="#{elem.awayTeam}" />
            </td>
            
            <td>
                <h:inputText id="homeS"   value="#{elem.homeScore}" size="2" >
                   <f:convertNumber maxFractionDigits="1" type="number" integerOnly="true" />             
                 </h:inputText>
            </td>
            <td>
                <h:inputText id="awayS"   value="#{elem.awayScore}" size="2" />
            </td>
             <td>
                 <h:form>
                     <h:commandButton   value=" Bet " class="w3-btn-block w3-teal" action="#{userBean.setGameBet(elem.matchNumber , elem.homeScore , elem.awayScore)}"   />     
                 </h:form>
            </td>
            </h:form>
       </tr>
            </ui:repeat>
        </table> 
    </h:body>
</html>



the Java Code :

Java
package users;

import static DataBase.Constants.IsEmailExist;
import DataBase.PrelogInQueries;
import Games.matchBean;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import logging.MainLogger;
import logging.*;


@ManagedBean( name="userBean" )
@SessionScoped 
public class UserBean implements Serializable {  

    private static List<User> tblScore ; 
    private String firstName= "First Name "; 
    private String lastName = "Last Name ";
    private String email = "Email";
    private String userName = "User Name";
    private int totalPoints ;
    private String password = "Password"; 
    private  static Logger logger = LoggerFactory.getLogger();
    private static PrelogInQueries login ; 
    //private List<Game> temp ; 
    private List<matchBean> matchList ; 
    public UserBean() 
    {
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }


    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getTotalPoints() {
        return totalPoints;
    }

    public void setTotalPoints(int totalPoints) {
        this.totalPoints = totalPoints;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public List<User> getTblScore() {
        return tblScore;
    }

    public void setTblScore(List<User> tblScore) {
        this.tblScore = tblScore;
    }

    public static PrelogInQueries getLogin() {
        return login;
    }

    public static void setLogin(PrelogInQueries login) {
        UserBean.login = login;
    }

    public List<matchBean> getMatchList() {
        return matchList;
    }

    public void setMatchList(List<matchBean> matchList) {
        this.matchList = matchList;
    }

    
    

    public String verifyLogin()
    {
        logger.log(Logger.LEVEL.INFO, "Insert to verifyLogin with email :" + email );
        login = new PrelogInQueries();
        boolean verified = false ; 
        verified = login.verifyMail(email , password ) ; 
        //userName = login.getUserName(email);
        //tblScore = new ArrayList(); 
        try { 
            tblScore =  login.loadTableScore();
            //temp = login.getRoundInfo();
            for ( int i = 0 ; i<tblScore.size() ; i++ )
            {
                logger.log(Logger.LEVEL.INFO, "tblScore :" + tblScore.get(i).getUserName() + "  " + tblScore.get(i).getTotalPoints() );
            }
        } catch (SQLException ex) {
            java.util.logging.Logger.getLogger(UserBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        if ( verified ==false  ) 
         return "/index.xhtml";
        else 
        {
         
        return "/welcome.xhtml"; 
        }
    }
    
       public String nextRound()
    {
        try { 
            matchList = login.getRoundInfo2();
            printArray ();
            logger.log(logging.Logger.LEVEL.INFO, "nextRound ");
        } catch (SQLException ex) {
           logger.log(Logger.LEVEL.INFO, " catch EXCEPTION ERROR : nextRound() " ) ;
        }
        return "/nextround.xhtml";
    }
       
    public void printArray () 
    {
        logger.log(logging.Logger.LEVEL.INFO, "printArray "); 
        for (int i = 0 ; i <matchList.size() ; i ++ )
        {
          logger.log(logging.Logger.LEVEL.INFO, "USER_BEAN =  Game # " +matchList.get(i).getMatchNumber() + " @ "+ matchList.get(i).getHomeTeam() + " vs " + matchList.get(i).getAwayTeam() +"  "+ matchList.get(i).getHomeScore() +"  "+ matchList.get(i).getAwayScore() ) ;   
        }
    } 
    
    public void setGameBet( int gamenumber , int hScore , int aScore   )
    {
        logger.log(logging.Logger.LEVEL.INFO, "*** setGameBet ***    "   + gamenumber + " = " + hScore + " - " + aScore );
        printArray();
        boolean t = setBet ( gamenumber , hScore ,aScore); 
        logger.log(logging.Logger.LEVEL.INFO, "*** Is setGameBet Done secsessfully ?: "   + t );
        printArray();
    }
    
     public boolean setBet( int gamenumber ,  int home , int away)
    {
        int indexToUpDate = getGameIndex (gamenumber) ; 
        if ( indexToUpDate == -1 )
        {
            return false ; 
        }
        else 
        {
           logger.log(logging.Logger.LEVEL.INFO, "*** Match Number Found !!  ***   match number: "   + gamenumber + " = " + home + " - " + away );
            matchBean toUpdate = matchList.get(indexToUpDate);
            toUpdate.setHomeScore(home);
            toUpdate.setAwayScore(away);
            matchList.set(indexToUpDate, toUpdate) ; 
            return true ; 
        }
    }
    
    public int getGameIndex (int matchNum ) 
    {   
         for ( int i = 0 ; i <matchList.size() ; i ++ )
         {
            
             if ( matchList.get(i).getMatchNumber() == matchNum )
             {     
                 logger.log(logging.Logger.LEVEL.INFO, "*** getGameIndex ***    i="+ i );
                 return i ; 
             }      
         }
         return -1 ; 
    }
    
      
  
}


What I have tried:

look on google , stackoverflow , and many other sites
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900