الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكل في اضافة كلاس في صفحة JSF

بدأه lovely_ned في 28 يونيو 2011 · 1 رد · 677 مشاهدة · في JavaEE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

عندي كلاس تقوم بالبحث في قاعدة البيانات

package Test;

import java.io.PrintWriter;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.commons.beanutils.RowSetDynaClass;


public class Recherche {


	private int Type;
	private String  Rech, SqlStr;
	private static RowSetDynaClass alerte;

	public RowSetDynaClass getRecherche (String Rech1, int Type1) 
	{

		Rech= Rech1 ; Type=Type1; 

		BDD con = new BDD();
		Statement stmt;

		try {
			stmt = con.getCon().createStatement();
			if (Type ==1) //Article
			{
				SqlStr="Select NOMARTICLE, NSERIE from DC_ARTIICLE where NOMARTICLE like '%" + Rech + "%' or NSERIE LIKE '%"+ Rech +"%'";			
			}
			else if (Type ==2)//Demandeur
			{

				}



			ResultSet rs = stmt.executeQuery(SqlStr);

			  RowSetDynaClass rs1 = new RowSetDynaClass(rs, false); 
		      alerte=rs1;
		      stmt.close();
		      con.getCon().close();

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return alerte;
	}


}

وهذه هي صفحة JSF

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

    <%@page import="org.apache.commons.beanutils.RowSetDynaClass"%>


<%@page import="Test.Recherche"%>

<%@page import="java.util.Locale"%>
<%@page import ="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Recherche</title>
</head>
<body>
 <h:form id="Rech">        
<table border="0" cellpadding="0" cellspacing="0" width="477" style="border-collapse:
 collapse;width:358pt">
   <colgroup>
     <col width="120" style="width: 90pt"><col width="80" style="width: 60pt">
     <col width="169" style="width: 127pt"><col width="108" style="width: 81pt">
   </colgroup>
   <tr height="34" style="height: 25.5pt">
     <td height="34" width="220" style="height: 25.5pt; width: 90pt; vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border-left: medium none; border-right: medium none; border-top: .5pt solid #FFCC66; border-bottom: .5pt solid #FFCC66; padding-left: 1px; padding-right: 1px; padding-top: 1px">
     <b><font face="Calibri" size="4">Mot recherché:</font></b></td>
     <td colspan="3" width="357" style="width: 268pt; text-align: center; vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; white-space: nowrap; border-left: medium none; border-right: .5pt solid #FFCC66; border-top: .5pt solid #FFCC66; border-bottom: .5pt solid #FFCC66; padding-left: 1px; padding-right: 1px; padding-top: 1px">
     <h:inputText size="40" style=" width : 403px;" id="rech"/></td>
   </tr>
   <tr height="9" style="height: 6.75pt">
     <td height="9" style="height: 6.75pt; vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px">
     </td>
     <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"> </td>
     <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"> </td>
     <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border-left: medium none; border-right: .5pt solid #FFCC66; border-top: medium none; border-bottom: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px">
      </td>
   </tr>
   <tr height="257" style="height: 192.75pt">
   <td colspan="4" height="257" style="height: 192.75pt; text-align: cleft; vertical-align: top; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; white-space: nowrap; border-left: .5pt solid #FFCC66; border-right: .5pt solid #FFCC66; border-top: medium none; border-bottom: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px">


<%
Recherche Rech= new Recherche();
RowSetDynaClass rs = Rech.getRecherche("gg",1);
request.setAttribute("results", rs);
%>  

<display:table name="requestScope.results.rows" />                   
 </td>
   </tr>
   <tr height="8" style="height: 6.0pt">
     <td height="8" style="height: 6.0pt; vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px">
     </td>
     <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"> </td>
     <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"> </td>
     <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border-left: medium none; border-right: .5pt solid #FFCC66; border-top: medium none; border-bottom: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px">
      </td>
   </tr>
   <tr height="38" style="height: 28.5pt">
     <td colspan="3" height="38" style="height: 28.5pt; text-align: center; vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; white-space: nowrap; border-left: .5pt solid #FFCC66; border-right: medium none; border-top: .5pt solid #FFCC66; border-bottom: .5pt solid #FFCC66; padding-left: 1px; padding-right: 1px; padding-top: 1px">
      </td>
     <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border-left: medium none; border-right: .5pt solid #FFCC66; border-top: .5pt solid #FFCC66; border-bottom: .5pt solid #FFCC66; padding-left: 1px; padding-right: 1px; padding-top: 1px">
     <h:commandButton   style=" width : 96px; float:right" value="Valider" id="Rech3"/></td>
   </tr>
 </table>
 </h:form>
</body>
</html>
</f:view>

لكن كيف يمكن ان اقوم بالبحث في الكلاس عن طريق القيمة الموجودة في InputText

#2

أخى ..

أنصحك أن تقرأ عن ال JSF قبل أن تبدأ بكتابة برامج بها ..

لأن الكود بالأعلى لا أرى فيه أي ملامح ال JSF اللهم إلا بإستخدامك لل JSF tag lib ..

...

بالنسبه لسؤالك ..

فبإمكانك عمل bind لل input text ...

و بداخل الدالة التى تقوم بتنفيذ ال action .. تستطيع أن تحصل على القيمه ..

مواضيع مشابهة