I am a JSF 2.0 newbie, and I am trying to build an scheduler.
So far everything has gone pretty well in terms of using primefaces and JSF tags. However I have a hard time using p:schedule tag.
At the very list I just want the calendar (agenda) to show up in my page, before I move on to the next part and add events.
My question is that shouldn't this code at least generate something in my page?
Here is my scheduleBean.java
#ManagedBean(name="scheduler")
#ViewScoped
public class SchedulerBean extends PageCodeBase implements Serializable {
private static final long serialVersionUID = -1426310201082465397L;
private String loggedInUser;
private boolean authorizeduser=false;
private boolean showUnauthorizeduserMessage=true;
private String theme;
private AuthorizeduserManager AUM = (AuthorizeduserManager)getManagedBean("AuthorizeduserManager");
private ScheduleModel eventModel;
public void pageOnLoad(){
this.setLoggedInUser(getFacesContext().getExternalContext().getRemoteUser());
this.checkAuthorization();
this.retriveTheme();
this.eventModel = new DefaultScheduleModel();
}
private void checkAuthorization(){
ArrayList<Authorizeduser> athorizedUser= new ArrayList<Authorizeduser>();
athorizedUser.addAll(AUM.getAuthorizeduser());
for(Authorizeduser au:athorizedUser){
if (loggedInUser.equalsIgnoreCase(au.getEmail())){
setAuthorizeduser(true);
showUnauthorizeduserMessage = false;
return;
}
}
}//end checkAuthorization
private void retriveTheme(){
if(authorizeduser){
this.theme = AUM.findAuthorizeduserByEmail(loggedInUser).getThemepref();
}else{
this.theme = "blitzer";
}
}
private void persistTheme(String theme){
//System.out.println("persistTheme was called");
ArrayList<Authorizeduser> athorUser= new ArrayList<Authorizeduser>();
athorUser.addAll(AUM.getAuthorizeduser());
for(Authorizeduser au:athorUser){
if (loggedInUser.equalsIgnoreCase(au.getEmail())){
try {
au.setThemepref(theme);
AUM.updateAuthorizeduser(au);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
//Getters and setters
public String getLoggedInUser() {
return loggedInUser;
}
private void setLoggedInUser(String loggedInUser) {
this.loggedInUser = loggedInUser;
}
public boolean isAuthorizeduser() {
return authorizeduser;
}
private void setAuthorizeduser(boolean authorizeduser) {
this.authorizeduser = authorizeduser;
}
public boolean isshowUnauthorizeduserMessage() {
return showUnauthorizeduserMessage;
}
public void setshowUnauthorizeduserMessage(boolean showUnauthorizeduserMessage) {
this.showUnauthorizeduserMessage = showUnauthorizeduserMessage;
}
public String getTheme() {
return theme;
}
public void setTheme(String theme){
this.theme = theme;
this.persistTheme(theme);
}
public String logout() {
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
//System.out.println("logoutRequested");
return "logout";
}
public ScheduleModel getEventModel() {
return eventModel;
}
public void setEventModel(ScheduleModel eventModel) {
this.eventModel = eventModel;
}
}
here is my MasterLayout.xhtml
<f:view>
<!-- WelcomeBar -->
<div id="WelcomeBar">
<ui:include src="/resources/templates/WelcomeBar.xhtml"></ui:include>
</div>
<f:event listener="#{scheduler.pageOnLoad }" type="preRenderView"></f:event>
<h:form styleClass="form" id="form1" height="30">
<p:panel>
<div id="Header">
<ui:include src="/resources/templates/Header.xhtml"></ui:include>
</div>
<div id="content">
<ui:insert name="content"></ui:insert>
</div>
<div id="Footer">
<ui:include src="/resources/templates/Footer.xhtml"></ui:include>
</div>
</p:panel>
</h:form>
</f:view>
</h:body>
And here is my schedule.xhtml which contain p:schedule tag:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
template="/resources/templates/MasterLayout.xhtml"
xmlns:p="http://primefaces.org/ui">
<!-- Content Properties -->
<ui:define name="content">
<p:schedule value="#{scheduler.eventModel}" widgetVar="myschedule">
</p:schedule>
</ui:define>
</ui:composition>
Just FYI, I created a simple page text.xhtml, and it works. so it must be related to the way I am templating:
<h:body>
<f:view>
<h:form styleClass="form" id="form1" height="30">
<p:panel>
<f:event listener="#{scheduler.pageOnLoad }" type="preRenderView"></f:event>
<h:outputText value="test"/>
<p:schedule value="#{scheduler.eventModel}" widgetVar="myschedule">
</p:schedule>
</p:panel>
</h:form>
</f:view>
</h:body>
Related
This question already has answers here:
Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable
(18 answers)
Closed 6 years ago.
I am getting below error when I run my login jsf page.
I think that my valider() function in my managed Bean is the issue but I didn't find the way
Authenticate function in my ejb:
#Override
public Client authentificate(String login, String pwd) {
Client client=null;
Query query=entityManager.createQuery("select c from Client c where c.login=:l and c.pwd=:p");
query.setParameter("l", login).setParameter("p",pwd);
try {
client=(Client) query.getSingleResult();
} catch (Exception e) {
client=null;
}
return client;
}
Managed bean:
#ManagedBean
#SessionScoped
public class LoginClientBean {
#EJB
GestionClientLocal local;
private String login;
private String pwd;
private boolean connected;
public static Client client;
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
String message=null;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public boolean isConnected() {
return connected;
}
public void setConnected(boolean connected) {
this.connected = connected;
}
public Client getClient() {
return client;
}
public String valider(){
String nav =null;
client=local.authentificate(login, pwd);
if (client != null){
nav="/pages/yes?faces-redirect=true";
}else {
nav="/pages/no?faces-redirect=true";
}
return nav;
}
public String deconnexion(){
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().clear();
return "/pages/login?faces-redirect=true";
}
}
JSF Page:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<title>Flate Signup And Login Form with Flat Responsive template :: w3layouts</title>
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
<h:outputStylesheet library="css" name="style.css"></h:outputStylesheet>
<h:outputScript type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </h:outputScript>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2">
<h:outputText value="login" />
<p:inputText value="#{loginClientBean.login}" />
<h:outputText value="password" />
<p:password value="#{loginClientBean.pwd}" />
<p:commandButton value="login" action="#{loginClientBean.valider()}" ajax="false"/>
</h:panelGrid>
</h:form>
</h:body>
</html>
Remove () from action method
<p:commandButton value="login" action="#{loginClientBean.valider}" ajax="false"/>
Give name for your managed bean (note it should work without specifying name also)
#ManagedBean(name="loginClientBean ")
#SessionScoped
public class LoginClientBean {
.....
}
If you are using JSF 2.2 replace jdk with 1.7 and above
.Finally give proper build before deploying
Also have a look into balu c solution https://stackoverflow.com/a/30128396/4036926
I have a login form ,a jsf backing login bean ,and a user details service.
Although the user is authenticated he is not redirected to the landing page.
The bean authenticates the user thru the UserDetailsService w/o any problem.
package com.emredincer.yetki.bean;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.security.sasl.AuthenticationException;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import com.emredincer.yetki.entity.Kullanici;
import com.emredincer.yetki.service.IKullaniciService;
#ManagedBean(name = "loginBean")
#RequestScoped
public class LoginBean {
private String username = null;
private String password = null;
#ManagedProperty(value="#{authenticationManager}")
private AuthenticationManager authenticationManager = null;
#ManagedProperty("#{KullaniciServiceImpl}")
private IKullaniciService kullaniciServis;
private Kullanici kullanici = new Kullanici();
public String login(){
try{
Authentication request = new UsernamePasswordAuthenticationToken(this.getUsername(), this.getPassword());
Authentication result = authenticationManager.authenticate(request);
SecurityContextHolder.getContext().setAuthentication(result);
}
catch(Exception e){
e.printStackTrace();
return "incorrect";
}
return "correct";
}
public String logout(){
SecurityContextHolder.clearContext();
return "loggedout";
}
public AuthenticationManager getAuthenticationManager() {
return authenticationManager;
}
public void setAuthenticationManager(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public IKullaniciService getKullaniciServis() {
return kullaniciServis;
}
public void setKullaniciServis(IKullaniciService kullaniciServis) {
this.kullaniciServis = kullaniciServis;
}
public Kullanici getKullanici() {
return kullanici;
}
public void setKullanici(Kullanici kullanici) {
this.kullanici = kullanici;
}
}
<http auto-config="true">
<intercept-url pattern="/web/*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<intercept-url pattern="/**" access="ROLE_USER" />
<form-login login-page="/web/login.xhtml"
authentication-success-handler-ref="successHandler"
/>
</http>
<authentication-manager alias="authenticationManager">
<authentication-provider user-service-ref="kullaniciDetayServisi" />
</authentication-manager>
</beans:beans>
public class CustomAuthSuccessHandler implements AuthenticationSuccessHandler {
public void onAuthenticationSuccess(HttpServletRequest arg0,
HttpServletResponse arg1, Authentication arg2) throws IOException,
ServletException {
arg1.sendRedirect(arg0.getContextPath() + "/main.xhtml");
}
}
<!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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
</h:head>
<h:body>
<div align="center" style="">
<h:form id="loginFormId" prependId="false">
<div id="loginFieldsPnlId">
<div id="loginFieldUsrContId">
<h:outputText id="outTxtUserNameId" value="Username: " name="outTxtUserNameNm"></h:outputText>
<h:inputText id="userName" required="true" value="#{loginBean.username}" requiredMessage="Please enter username"></h:inputText>
<h:outputLabel id="outLblUserNameId" for="userName" name="outLblUserNameNm"></h:outputLabel>
</div>
<div id="loginFieldPassContId">
<h:outputText id="outTxtPasswordId" value="Password: " name="outTxtPasswordNm"></h:outputText>
<h:inputSecret id="password" required="true" value="#{loginBean.password}" requiredMessage="Please enter password" name="inTxtPasswordNm"></h:inputSecret>
<h:outputLabel id="outLblPasswordId" for="password" name="outLblPasswordNm"></h:outputLabel>
</div>
</div>
<div id="loginBtnPanelId">
<h:commandButton id="btnLoginId" value="Login" action="#{loginBean.login}" styleClass="loginPanelBtn" ajax="false"></h:commandButton>
<h:commandButton id="btnCancelId" value="Cancel" action="#{loginBean.cancel}" styleClass="loginPanelBtn" immediate="true" update="loginFormId"></h:commandButton>
</div>
</h:form>
</div>
<div>
<h:messages></h:messages>
</div>
</h:body>
</html>
i resolved the issue by modifying the login method's return statement
public String login(){
try{
Authentication request = new UsernamePasswordAuthenticationToken(this.getUsername(), this.getPassword());
Authentication result = authenticationManager.authenticate(request);
SecurityContextHolder.getContext().setAuthentication(result);
}
catch(Exception e){
e.printStackTrace();
return "incorrect";
}
return "/main.xhtml";
}
I'm new in JSF and PrimeFaces and I can't understand why my setter for selected value doesn't set:
I've got main XHTML in which after click on <p:commandButton> I want to change selected row. But after changing selection of the row on data setter setSelectedBook() get null value on entrance.
I already set selection and rowKey for <p:dataTable>.
It looks like :
main XTML:
<?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:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://xmlns.jcp.org/jsf/html"
>
<body>
<ui:composition template="./../../WEB-INF/pagesTemplate.xhtml">
<form>
<ui:define name="content">
<p:dataTable id="eventsDT" var="book" value="#{bookHolder.books}"
selectionMode= "single" selection="#{bookController.selectedBook}"
rowKey="#{book.id}">
<p:ajax event="rowSelect"/>
<p:ajax event="rowDblselect" listener="#{bookController.onDoubleRowSelect}" />
<p:column headerText="ID">
<h:outputText value="#{book.id}" />
</p:column>
<p:column headerText="Title">
<h:outputText value="#{book.longName}" />
</p:column>
</p:dataTable>
</ui:define>
<ui:define name="right">
<h:panelGrid columns="1" cellpadding="5">
<p:commandButton id="btnEdit" value="Edit"
action="#{navigationController.moveToBookEditPageSimple}"
style="width: 100px;height: 28px; margin-left: 10%"/>
</h:panelGrid>
</ui:define>
</form>
</ui:composition>
</body>
</html>
BookController that can't get value:
#Named("bookController")
#SessionScoped
#Local(BookView.class)
public class BookController implements Serializable {
public BookController() {
navigator = new NavigationController();
}
NavigationController navigator;
#Inject
BookHolder bookHolder;
private Book selectedBook;
public Book getSelectedBook() {
return selectedBook;
}
public void setSelectedBook(Book selectedBookValue) {
this.selectedBook = selectedBookValue;
}
public void onDoubleRowSelect(SelectEvent event) throws IOException {
String str = navigator.showPage("BookEdit");
FacesContext.getCurrentInstance().getExternalContext().redirect(str + ".xhtml");
}
}
BookHolderBean that contains data:
#Named("bookHolder")
#ApplicationScoped
public class BookHolder {
public BookHolder() {
}
#PostConstruct
void setValues() {
this.books = new ArrayList<>();
for (int i = 0; i < 10; i++) {
this.books.add(new Book(new ParkType(i, i,
"Book #: " + i + " (long name)",
"Book #: " + i + " (short name)",
"Book #: " + i + " (note)")));
}
}
private List<Book> books;
public List<Book> getBooks() {
return books;
}
public void setBooks(List<Book> parkTypes) {
this.books = parkTypes;
}
}
Class Book:
public class Book extends MainEntitie<Book> implements Serializable, SelectableDataModel<Book> {
#Inject
BookHolder bookHolder;
private final String longName;
private final String shortName;
public Book(BookBase sd) {
super(sd.getId(), false, false, sd.getNote());
this.longName = sd.getLongName();
this.shortName = sd.getShortName();
}
public String getLongName() {
return longName;
}
public String getShortName() {
return shortName;
}
#Override
public int getId() {
return super.getId();
}
#Override
public Object getRowKey(Book t) {
return t.getId();
}
#Override
public Book getRowData(String string) {
for (Book app : bookHolder.getBooks()) {
if (app.getId() == Integer.parseInt(string)) {
return app;
}
}
return null;
}
}
Since you use ui:define, I assume there is a ui:include in your template file (pagesTemplate.xhtml).
If so, that is great, but your included page has some unnecessary stuff, e.g. html and body tag (by the way: use h:body). No need for that.
See second part of this posting to learn how to include an xhtml file into another one.
You will notice that the content of ui:define is kind of "cut&pasted" into the your template file.
So, what about your form tag? It's being ignored (at least, I guess it won't be a parent of your datatable).
Make the h:form (again, use JSF's h:form instead of HTML form) a child of ui:define,
like:
<ui:composition template="/WEB-INF/template.xhtml"
xmlns=.....>
<ui:define name="content">
<h:form>
<p:dataTable ...>
...
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
Mojara 2.1.21
I'm using primefaces editor component p:editor. The value attribute in editor is a complex EL-Statement.
<h:form>
<p:datatable value="#{bean.getItems}" var="item">
<p:column>
<p:editor value="bean.A(item).value" />
</p:column>
</p:datatable>
</h:form>
class Bean {
public Entity A (Item i) { return ...}
}
class Entity {
public String getValue();
public void setValue(String);
}
The getter Entity.getValue() is called, but the setter Entity.serValue(String) is not called, if form is submitted.
I suppose it has nothing to do with editor but a common feature of EL. How can I instruct the editor to call a setter if some changes will be made in editor by a user ?
UPDATE
The variant <p:editor value="#{multiEditorBacking.eval(editor).text}" id="textArea" /> has trouble if setter will be called. But <p:editor value="#{editor.text}" id="textArea" /> is ok. The following examples can be used for testing.
<!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://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:o="http://omnifaces.org/ui" xmlns:pe="http://primefaces.org/ui/extensions">
<ui:composition>
<h:head></h:head>
<h:body>
<h:form id="formId">
<p:dataTable value="#{multiEditorBacking.editors}" var="editor" rowIndexVar="index" >
<p:column>
<p:commandButton value="Refresh" actionListener="#{multiEditorBacking.onRefresh(index)}" update="textArea"
process="#this" />
<p:editor value="#{multiEditorBacking.eval(editor).text}" id="textArea" />
<!-- <p:editor value="#{editor.text}" id="textArea" /> -->
</p:column>
</p:dataTable>
<p:commandButton value="Save" />
</h:form>
</h:body>
</ui:composition>
</html>
MultiEditorBean.java
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
#SessionScoped
#Named
public class MultiEditorBacking implements Serializable{
private List<MultiPojo> editors;
private HashMap <Integer, MultiPojo> hash = new HashMap<Integer, MultiPojo>();
#PostConstruct
public void init(){
editors = new ArrayList<MultiPojo>();
MultiPojo m = new MultiPojo();
m.setText("hey1");
editors.add(m);
hash.put(1, m);
m=new MultiPojo();
m.setText("adf2");
editors.add(m);
hash.put(2, m);
m=new MultiPojo();
m.setText("cjd3");
editors.add(m);
hash.put(3, m);
}
public MultiPojo eval (MultiPojo m){
return m;
}
public void onRefresh (int index){
}
public List<MultiPojo> getEditors() {
return editors;
}
public void setEditors(List<MultiPojo> editors) {
this.editors = editors;
}
public HashMap <Integer, MultiPojo> getHash() {
return hash;
}
public void setHash(HashMap <Integer, MultiPojo> hash) {
this.hash = hash;
}
}
MultiPojo.java
public class MultiPojo {
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
This works for me, in Mojarra 2.2.5, using EL 2.2. Are you sure you've got that EL version enabled which allows method parameter passing? You need a Servlet 3.x container available (such as Tomcat 7) or you'll need to add the library yourself. However, it seems you've got it as #{multiEditorBacking.eval(editor).text} value for your editors is being properly evaluated.
By the way, your <ui:composition> surrounding <h:head /> and <h:body /> is unecessary. Another thing I don't like from your code is the use of #SessionScoped for pure view matters. Go with #ViewScoped unless you're explicitly dealing with session related stuff.
#SessionScoped
#Named
public class MultiEditorBacking implements Serializable {
private List<MultiPojo> editors;
private HashMap<Integer, MultiPojo> hash = new HashMap<Integer, MultiPojo>();
public MultiEditorBacking() {
editors = new ArrayList<MultiPojo>();
MultiPojo m = new MultiPojo();
m.setText("hey1");
editors.add(m);
hash.put(1, m);
m = new MultiPojo();
m.setText("adf2");
editors.add(m);
hash.put(2, m);
m = new MultiPojo();
m.setText("cjd3");
editors.add(m);
hash.put(3, m);
}
public MultiPojo eval(MultiPojo m) {
return m;
}
public void onRefresh(int index) {
System.out.println("Editor " + index + " refreshed");
}
public List<MultiPojo> getEditors() {
return editors;
}
public void setEditors(List<MultiPojo> editors) {
this.editors = editors;
}
public HashMap<Integer, MultiPojo> getHash() {
return hash;
}
public void save() {
System.out.println("Editors: " + editors);
}
public void setHash(HashMap<Integer, MultiPojo> hash) {
this.hash = hash;
}
public class MultiPojo {
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
#Override
public String toString() {
return "MultiPojo [text=" + text + "]";
}
}
}
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head />
<h:body>
<h:form id="formId">
<p:dataTable value="#{multiEditorBacking.editors}" var="editor"
rowIndexVar="index">
<p:column>
<p:commandButton value="Refresh"
actionListener="#{multiEditorBacking.onRefresh(index)}"
update="textArea" process="#this" />
<p:editor value="#{multiEditorBacking.eval(editor).text}"
id="textArea" />
</p:column>
</p:dataTable>
<p:commandButton value="Save" action="#{multiEditorBacking.save}" />
</h:form>
</h:body>
</html>
See also:
Using EL 2.2 with Tomcat 6.0.24
The solution was to use brackets in EL to get setter called.
<p:editor value="#{(multiEditorBacking.eval(editor)).text}"
id="textArea" />
I am getting error while running this snippet as /facelet/crew/objectMapGossip.xhtml #14,94 value="#{objcetMapBean.searchCrewParam.staffNum}": Property 'staffNum' not readable on type java.lang.String
please help me out from this small error .. I am new to jsf so stucking at things basic ...
Thanks in advance :-)
This is my backing bean...
import javax.faces.bean.ManagedBean;
#ManagedBean(name = "objcetMapBean")
public class ObjectMapGossip {
private SearchCrew1 searchCrewParam = new SearchCrew1("212","kart","asd");
public SearchCrew1 getSearchCrewParam() {
return searchCrewParam;
}
public void setSearchCrewParam(SearchCrew1 searchCrewParam) {
this.searchCrewParam = searchCrewParam;
}
public String search() {
return "success";
}
}
class SearchCrew1 {
public SearchCrew1() {
super();
}
/**
* #param staffNum
* #param surName
* #param rank
*/
public SearchCrew1(String staffNum, String surName, String rank) {
super();
this.staffNum = staffNum;
this.surName = surName;
this.rank = rank;
}
private String staffNum;
private String surName;
private String rank;
public String getStaffNum() {
return staffNum;
}
public void setStaffNum(String staffNum) {
this.staffNum = staffNum;
}
public String getSurName() {
return surName;
}
public void setSurName(String surName) {
this.surName = surName;
}
public String getRank() {
return rank;
}
public void setRank(String rank) {
this.rank = rank;
}
}
This is my jsf page
<?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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:body>
<ui:composition template="/facelet/layout/mainlayout.xhtml">
<ui:define name="content">
<h:form>
<div align="left">
<h:outputText value="Staff Number: " />
<h:inputText id="staffnum" size="6" value="# {objcetMapBean.searchCrewParam.staffNum}" />
<h:outputText value="Surname: " />
<h:inputText id="surname" size="10" maxlength="25" value="# {objcetMapBean.searchCrewParam.surName}" />
<h:outputText value="Rank: " />
<h:inputText id="rank" size="3" value="#{objcetMapBean.searchCrewParam.rank}" />
<h:commandButton value="Search" action="#{objcetMapBean.search}" />
</div>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
We can use h:dataTable from jsf tag and map easily.
http://www.mkyong.com/jsf2/jsf-2-datatable-example/