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

JSF Events Listener

بدأه javadeveloper في 23 يونيو 2012 · 1 رد · 871 مشاهدة · في JavaEE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

انا حاولت استخدم value change listener باستخدام tag وباستخدام attribute الفكرة الاولى غير واضحة بالنسبة لي ولا تعمل اساسا في الحالة الثانية تعمل بشكل جيد

استخدام Tag عملت 3 ملفات -> ملف index.xhtml

<h3>Country</h3>
				<h:selectOneMenu value="#{event.country}" onchange="submit()">
					<f:valueChangeListener type="org.jsf.model.ValueListener"/>
					<f:selectItems value="#{event.countries}"/>
				</h:selectOneMenu>



	<h3>Capital</h3>
				#{event.capital}

-> ملف لل managed bean

	private String []countries={"Select","Egypt","United Kingdom","Kuwait","Saudi Arabia"};
	private String capital;
	private String country;
// getters and setters

->ملف للevent

public class ValueListener implements ValueChangeListener {
	String capital;
	@Override
	public void processValueChange(ValueChangeEvent event)
			throws AbortProcessingException {
		// TODO Auto-generated method stub


			if ("Egypt".equals(event.getNewValue())){
			capital = "cairo";
			}
			else if ("United Kingdom".equals(event.getNewValue())){
				capital = "London";
				}
			else if ("Kuwait".equals(event.getNewValue())){
				capital = "Kuwait";
				}
			else if ("Saudi Arabia".equals(event.getNewValue())){
				capital = "Riyadh";
				}
			else{
				capital = "";
			}

new Events().setCapital(capital);

مش متأكدة اذا كان هذا صحيح او لا وكيف اعرض العاصمة مع العلم اني عندما استخدمت attribute اشغل صح

وهذا الكود

<h3>Country</h3>
				<h:selectOneMenu value="#{event.country}" onchange="submit()"
				valueChangeListener="#{event.getCountryCapital}">
					<f:selectItems value="#{event.countries}"/>
				</h:selectOneMenu>

	<h3>Capital</h3>
				#{event.capital}

وهذه ال bean

private String []countries={"Select","Egypt","United Kingdom","Kuwait","Saudi Arabia"};
	private String capital;
	private String country;
// getters and setters

public void getCountryCapital(ValueChangeEvent event){
		System.out.println(event.getOldValue());
		System.out.println(event.getNewValue());
		if(event.getNewValue().equals("Egypt")) capital="Cairo";
		else if(event.getNewValue().equals("United Kingdom")) capital="London";
		else if(event.getNewValue().equals("Kuwait")) capital="Kuwait";
		else if(event.getNewValue().equals("Saudi Arabia"))capital="Riyadh";
		else if(event.getNewValue().equals("Select")) capital="";


		setCapital(capital);

	}
#2

ما المشكلة التي تواجيهنها بالضبط؟

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

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