Rss

Archives for : JSF

JSF- Build Error Handling (Empty Input Fields)

1. First, you build the xhtml file



	
		
	
	
		
			
			
#{msgs.namePrompt}: #{msgs.agePrompt}:

The correct label should be declared as:


and the correct error message should be declared as:


	#{msgs.agePrompt}:

with “for” as same as “name” of the target.

2. and then build user.java

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@Component("user")
@Scope("session")
public class User implements Serializable {
private String name;
private String age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}

JSF #TAG

this tutorial will be about xhtml using list item using java class.

  1. First, you initialized the index.xhtml the dynamic value of form.yearItems.

<h:selectOneMenu value="#{form.yearOfBirth}" required="true"> <f:selectItems value="#{form.yearItems}" /> </h:selectOneMenu>

2. Initialized the java class for getYearItems (remember! variable for yearItems must be declared getYearItems) and then return to other variables (integer or String)

public Collection<SelectItem> getYearItems() { return birthYears; }

3. Initialized birthYears (other variable) using private static (u must import Collection class) birthyears initialized using ArrayList<SelectItem>, just make sure that variable is just like below code:

private static Collection<SelectItem> birthYears; static { birthYears = new ArrayList<SelectItem>(); // The first item is a "no selection" item birthYears.add(new SelectItem(null, "Pick a year:", "", false, false, true)); for (int i = 1900; i < 2020; ++i) birthYears.add(new SelectItem(i)); }

public Collection<SelectItem> getYearItems() { return birthYears; }

4. Initialized the get function to get your input variable (please using the right-click-> source->getters&letters)


private Integer yourPokemon;


public Integer getYourPokemon() {
return yourPokemon;
}


public void setYourPokemon(Integer yourPokemon) {
this.yourPokemon = yourPokemon;
}