How to handle h:inputText validation? - validation

I'd like to display an error next to the fields that are wrong. I have that code for my page :
<!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://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="/WEB-INF/templates/basic.xhtml">
<ui:define name="content">
<h:form>
<h:panelGrid columns="3">
<h:outputText value="Firstname"/>
<h:inputText id="firstName" value="#{account.firstName}" required="true">
<f:validator validatorId="stringAlphaValidator"/>
</h:inputText>
<h:message for="firstName" errorStyle="color:red; display:block"/>
<h:outputText value="Lastname"/>
<h:inputText id="lastName" value="#{account.lastName}" required="true">
<f:validator validatorId="stringAlphaValidator"/>
</h:inputText>
<h:message for="lastName" errorStyle="color:red; display:block"/>
<h:outputText value="Login"/>
<h:inputText id="login" value="#{account.login}" required="true">
<f:validator validatorId="stringAlphaValidator"/>
</h:inputText>
<h:message for="login" errorStyle="color:red; display:block"/>
<h:outputText value="Password"/>
<h:inputText id="password" value="#{account.password}" required="true">
</h:inputText>
<h:message for="password" errorStyle="color:red; display:block"/>
<h:outputText value="Address"/>
<h:inputText id="address" value="#{account.address}" required="true">
<f:validator validatorId="stringAlphaNumericValidator"/>
</h:inputText>
<h:message for="address" errorStyle="color:red; display:block"/>
<h:outputText value="Email"/>
<h:inputText id="email" value="#{account.email}" required="true">
<f:validator validatorId="emailAddressValidator"/>
</h:inputText>
<h:message for="email" errorStyle="color:red; display:block"/>
</h:panelGrid>
<h:commandButton value="Register"/>
<h:messages globalOnly="true"/>
</h:form>
</ui:define>
</ui:composition>
</html>
If a field is empty and I press the Register button, I get that (here all fields are empty):
(sorry the error is in french. I don't know if it comes from my eclipse language or my tomcat server)
I didn't write this ! This is a text that my program writes on it's own somehow... How do I remove this ?
Also, this is a register page, I'd like to add to my DB the user (if the fields are right) and then change of page with the action login. How can I call a method to do that before it changes of page ?
If you need to see more code, like the validator classes, I can add it.

This should work.
<h:inputText id="lastName" value="#{account.lastName}" required="true" requiredMessage="Please enter your Lastname">
And the fields you validate, you can add a validatorMessage="<Message>"
** UPDATE *
If you want to use Bean Validation, like described in my comment,go this way:
// for example your NamesBean
#Named(value = "namesBean")
#SessionScoped
public class NamesBean {
// attributes
public void setFirstName(String firstName) {
this.firstName = firstName;
}
#Size(min=3, max=10, message="Min 3 and max 10 characters")
public String getFirstname() {
return firstName;
}
}
and the xhtml
<h:message for="lastName"/>
<h:inputText id="lastName" value="#{account.lastName}" required="true" requiredMessage="Please enter your Lastname">
Thats it.

I managed it this way (personnaly) :
<!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://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="/WEB-INF/templates/basic.xhtml">
<ui:define name="content">
<h:form>
<h:panelGrid columns="3">
<h:outputText value="Firstname"/>
<h:inputText id="firstName" value="#{account.firstName}" required="true" requiredMessage="The field is empty" validatorMessage="String is not valid (only characters a-z A-Z)">
<f:validateRegex pattern="[a-zA-Z]+"/>
</h:inputText>
<h:message for="firstName" errorStyle="color:red; display:block"/>
<h:outputText value="Lastname"/>
<h:inputText id="lastName" value="#{account.lastName}" required="true" requiredMessage="The field is empty" validatorMessage="String is not valid (only characters a-z A-Z)">
<f:validateRegex pattern="[a-zA-Z]+"/>
</h:inputText>
<h:message for="lastName" errorStyle="color:red; display:block"/>
<h:outputText value="Login"/>
<h:inputText id="login" value="#{account.login}" required="true" requiredMessage="The field is empty" validatorMessage="String is not valid (only characters a-z A-Z 0-9)">
<f:validateRegex pattern="[a-zA-Z0-9]+"/>
</h:inputText>
<h:message for="login" errorStyle="color:red; display:block"/>
<h:outputText value="Password"/>
<h:inputSecret id="password1" value="#{account.password1}" required="true" requiredMessage="Enter a password">
</h:inputSecret>
<h:message for="password1" errorStyle="color:red; display:block"/>
<h:outputText value=""/>
<h:inputSecret id="password2" value="#{account.password2}"/>
<h:outputText value=""/>
<h:outputText value="Address"/>
<h:inputText id="address" value="#{account.address}" required="true" requiredMessage="The field is empty" validatorMessage="Wrong address (eg.: 42bis My address)">
<f:validateRegex pattern="[a-zA-Z0-9]+ [a-zA-Z ]+"/>
</h:inputText>
<h:message for="address" errorStyle="color:red; display:block"/>
<h:outputText value="Email"/>
<h:inputText id="email" value="#{account.email}" required="true" requiredMessage="The field is empty" validatorMessage="The email is not valid">
<f:validateRegex pattern="^[a-z0-9._%+-]+#[a-z0-9.-]+\.[a-z]{2,4}$"/>
</h:inputText>
<h:message for="email" errorStyle="color:red; display:block"/>
</h:panelGrid>
<h:commandButton value="Register" action="#{account.action}"/>
<h:messages globalOnly="true"/>
</h:form>
</ui:define>
</ui:composition>
</html>

Related

Validations are not working except first tab of wizard and data loss between tabs

I am trying to use wizard with Primefaces (ViewScoped) . I created the page with 4 tabs. After navigating first tab, user reaches second tab and user enters some values to the input text fields at this second tab page. When the user goes the previous or next tab from second tab and comes back to this second tab all the entered values are lost except first tab. Also validations are not working except first tab.Is there a solution for this problem? Here is my html code:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
template="template/template.xhtml">
<ui:define name="body">
<h:graphicImage value="resources/myimage.jpg" />
<!-- First Tab -->
<h:form id="form">
<p:growl id="growl" sticky="true" showDetail="true"/>
<p:wizard flowListener="#{myView.onFlowProcess}" widgetVar="wiz">
<p:tab id="person" title="PERSON">
<p:panel header="">
<p:messages />
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="NAME :" />
<p:inputText value="#{myView.user.firstname}" label="Name" validatorMessage="NAME ERROR">
<f:validateRegex pattern="[a-zA-Z]{2,50}+"/>
</p:inputText>
<h:outputText value="SURNAME: *" />
<p:inputText value="#{myView.user.lastname}" label="Surname" validatorMessage="SURNAME ERROR">
<f:validateRegex pattern="[a-zA-Z]{2,60}+"/>
</p:inputText>
<h:outputText value="obligatory" style="color:red;"/>
</h:panelGrid>
</p:panel>
</p:tab>
<!-- ADDRESS -->
<p:tab id="address" title="ADDRESS">
<p:panel header="">
<p:messages />
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="cellular Phone" />
<p:inputMask id="cellularPhone" value="#{myView.user.cellularPhone}" mask="59999999999" required="true" requiredMessage="CELLULAR PHONE CANNOT BE EMPTY"/>
<h:outputText value="Cellular Phone :" style="color:red;" />
<h:outputText value="" />
<h:outputText value="Email :" />
<p:inputText value="#{myView.user.email}" />
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="country" value="country" />
<p:selectOneMenu id="country" value="#{dropDownView.country}" style="width:150px">
<p:ajax listener="#{dropDownView.onCountryChange}" update="city" />
<f:selectItem itemLabel="please Select" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{dropDownView.countries}" />
</p:selectOneMenu>
<p:outputLabel for="city" value="city" />
<p:selectOneMenu id="city" value="#{dropDownView.city}" style="width:150px">
<f:selectItem itemLabel="please Select" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{dropDownView.cities}" />
</p:selectOneMenu>
</h:panelGrid>
<p:separator />
<h:outputText value="obligatory" style="color:red;"/>
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="confirm" title="PAYMENT">
<p:panel header="">
<p:commandButton value="SAVE" action="#{myView.save}" update="growl" oncomplete="wiz.next();" process="#this" validateClient="true"/>
</p:panel>
</p:tab>
</p:wizard>
</h:form>
</ui:define>
</ui:composition>

jsf messages enqueued and not display

I have a jsf Form with fields, submit and messages for it
<h:form id="loginForm">
<h:outputText value="Введите логин и пароль:"/>
<h:panelGrid columns="2">
<h:outputLabel for="email" value="E-Mail:"/>
<h:inputText id="email" value="#{sign.email}" required="true" requiredMessage="Введите e-mail" validatorMessage="email должен быть вида abc#abc.abc">
<f:validateRegex pattern="[\w\.-]*[a-zA-Z0-9_]#[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
</h:inputText>
<h:outputLabel for="password" value="Password:"/>
<h:inputSecret converter="pwdConverter" id="password" value="#{sign.password}" required="true" requiredMessage="Введите пароль"/>
<h:commandButton action="#{sign.doLogin()}" value="Войти"/>
<h:commandLink action="/pages/register?faces-redirect=true" immediate="true" value="Зарегистрироваться"/>
</h:panelGrid>
<h:messages for="loginForm"/>
</h:form>
And it works fine: when I just click on the submit without input anything, it shows me a validation erros, but when I added a facebook-login button, I have a message in server log: Info: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=loginForm:email[severity=(ERROR 2), summary=(Введите e-mail), detail=(Введите e-mail)] for each field and validation messages not displayed on the page any more
there is how I added a fb-button:
<h:outputScript library="js" name="login.js"/>
<h:form id="loginForm">
<h:outputText value="Введите логин и пароль:"/>
<h:panelGrid columns="2">
<h:outputLabel for="email" value="E-Mail:"/>
<h:inputText id="email" value="#{sign.email}" required="true" requiredMessage="Введите e-mail" validatorMessage="email должен быть вида abc#abc.abc">
<f:validateRegex pattern="[\w\.-]*[a-zA-Z0-9_]#[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
</h:inputText>
<h:outputLabel for="password" value="Password:"/>
<h:inputSecret converter="pwdConverter" id="password" value="#{sign.password}" required="true" requiredMessage="Введите пароль"/>
<h:commandButton action="#{sign.doLogin()}" value="Войти"/>
<h:commandLink action="/pages/register?faces-redirect=true" immediate="true" value="Зарегистрироваться"/>
</h:panelGrid>
<h:messages for="loginForm"/>
</h:form>
<br/>
<div class="fb-login-button" data-max-rows="1" data-size="medium" data-show-faces="false" data-auto-logout-link="true"></div>
<div id="status"/>

JSF Primefaces form errors after failed validation

I am new to JSF/Java in general but have been trying to solve this for a few days now.
I have a form which gets stuck on validation. When all the entries are valid, it all works well. The minute I break validation (such as don't provide a required value), then the form gets stuck. One thing that happens is I cant correct the invalid entry it seems and repost. Also, where I had a cascading ajax call of a selectOneMenu, that suddenly starts failing...even though this is not the invalidated part of the form.
I notice that the cascading drop down seems to be throwing null pointer exceptions in its overridden equals method.
I am at a loss.
<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:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="/templates/layout.xhtml">
<ui:define name="content">
<p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>
<p:dialog modal="true" widgetVar="statusDialog" header="Status"
draggable="false" closable="false">
<p:graphicImage value="/resources/images/ajaxloadingbar.gif" />
</p:dialog>
<h:form id="form">
<p:panel id="panel"
header="Please ensure your personal details are accurate"
style="margin-bottom:10px;">
<p:messages id="msgs" />
<h:outputText
value="Please ensure your personal details are up to date and accurate within the Admin Direct system. Please note that this application only supports GMD customers, so unless you are within GMD, or are a user of the GMD Admin Direct service, please do not enter your details or attempt to use the application for administrative support." />
<h:panelGrid columns="3" cellpadding="5" id="grid">
<h:outputText value="First Name:" style="font-weight:bold" />
<p:inputText id="firstName"
value="#{personalDetailsBean.user.firstName}"
requiredMessage="First name is required..." style="width:250px" />
<p:message id="firstNameMessage" for="firstName" />
<h:outputText value="Last Name:" style="font-weight:bold" />
<p:inputText id="lastName"
value="#{personalDetailsBean.user.lastName}"
requiredMessage="Last name is required..." style="width:250px" />
<p:message id="lastNameMessage" for="lastName" />
<h:outputText value="Select Function:" style="font-weight:bold" />
<p:selectOneMenu id="functions"
value="#{personalDetailsBean.user.function}"
style="width:250px">
<f:selectItem itemLabel="Select Function" itemValue="" />
<f:selectItems value="#{personalDetailsBean.functions}" var="func"
itemLabel="#{func.functionName}" itemValue="#{func}" />
<f:converter converterId="functionConverter" />
</p:selectOneMenu>
<p:message id="functionMessage" for="functions" />
<h:outputText value="Select Site" style="font-weight:bold" />
<p:selectOneMenu id="sites"
value="#{personalDetailsBean.user.site}"
style="width:250px">
<f:selectItem itemLabel="Select Site" itemValue="" />
<f:selectItems value="#{personalDetailsBean.sites}" var="sit"
itemLabel="#{sit.siteName}" itemValue="#{sit}" />
<f:converter converterId="siteConverter" />
<p:ajax update="region" event="change" process="#this"/>
</p:selectOneMenu>
<p:message id="siteMessage" for="sites" />
<h:outputText value="Region" style="font-weight:bold" />
<h:outputText id="region"
value="#{personalDetailsBean.user.site.region.regionName}" />
<p:message id="regionMessage" for="region" />
<h:outputText value="Email" style="font-weight:bold" />
<p:inputText id="email" value="#{personalDetailsBean.user.email}"
required="true"
validatorMessage="Invalid email address format"
style="width:250px">
<f:validateRegex
pattern="[\w\.-]*[a-zA-Z0-9_]#[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
<f:validateLength minimum="2" />
</p:inputText>
<p:message id="emailMessage" for="email" />
</h:panelGrid>
<p:separator />
<p:commandButton value="Save" id="btnSubmit" actionListener="#{personalDetailsBean.saveUser}" process="#all" update="panel" />
</p:panel>
</h:form>
</ui:define>
</ui:composition>
</html>
any advice greatly appreciated.
Regards
SM

Submit button doesn't work correctly with ajax jsf 2.0 onblur validation

I'm trying to implement ajax client side validation with jsf 2.0 (primefaces).
I prefer onblur event rather than ontype, because it seems more user friendly. The problem is: my Register button has to be clicked twice to work correctly when a focus is inside an invalid field. 1st time we click - onblur event happens, 2nd time we click - submit happens (i suggest this is the reason). My code:
<html xmlns="http://www.w3c.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="template.xhtml">
<ui:define name="content">
<p:panel header="#{msg['register']}" style="width: 550px; align: left;">
<h:form>
<h:panelGrid columns="3" cellpadding="2">
<h:outputLabel for="name" value="#{msg['yourName']}:" />
<p:inputText id="name" value="#{userManagedBean.name}">
<f:validateLength maximum="20" />
<p:ajax update="msgName" event="blur" />
</p:inputText>
<p:message for="name" id="msgName" display="text"/>
<h:outputLabel for="userName" value="*#{msg['login']}:"/>
<p:inputText id="userName" value="#{userManagedBean.username}" label="UserName" required="true">
<f:validateLength minimum="5" maximum="20" for="userName"/>
<p:ajax update="msgUserName" event="blur"/>
</p:inputText>
<p:message for="userName" id="msgUserName"/>
<h:outputLabel for="password" value="*#{msg['password']}:" />
<p:password id="password" value="#{userManagedBean.password}" required="true">
<f:validator validatorId="confirmPasswordValidator" />
<f:attribute name="confirm" value="#{confirmPassword.submittedValue}" />
<f:ajax event="blur" execute="password confirm" render="m_password" />
</p:password>
<p:message id="m_password" for="password" />
<h:outputLabel for="confirm" value="*#{msg['retypePassword']}:" />
<p:password id="confirm" binding="#{confirmPassword}" required="true">
<f:ajax event="blur" execute="password confirm" render="m_password m_confirm" />
</p:password>
<p:message id="m_confirm" for="confirm" />
<h:outputLabel for="email" value="#{msg['email']}:"/>
<p:inputText id="email" value="#{userManagedBean.email}" label="email">
<f:validateRegex pattern="^([a-zA-Z0-9_\-\.]+)#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$" for="email"/>
<p:ajax update="msgEmail" event="blur"/>
</p:inputText>
<p:message for="email" id="msgEmail"/>
</h:panelGrid>
<ui:remove><p:captcha label="Captcha"/> </ui:remove>
<h:commandButton type="submit" value="#{msg['register']}" action="#{userManagedBean.register}"></h:commandButton>
</h:form>
</p:panel>
</ui:define>
</ui:composition>
</html>

JSF : dynamically loaded page commandButton not working

I have a page that contains a PrimeFaces accordion panel, in each panel is a PrimeFaces datatable. Below the datatable is a button "Add study" for example and when this button is click I want to dynamically load a page into a <h:panelGroup> using a <ui:include>. When the button is being click I want to dynamically change the src value from the <ui:include> so that my page is loaded in the <h:panelGroup>. Now the problem is the following:
My managed bean is set to #RequestScoped and when I click on my button nothing is being rendered.
If I set my managed bean to #SessionScoped the <h:panelGroup> is filled after the second click on the button, the first click doesn't do anything.
Used technologies : JSF2.0, PrimeFaces, Facelets
Here are some code snippets :
Main Page
<h:panelGroup id="content" layout="block">
<ui:include src="#{studyBean.includePage}"/>
</h:panelGroup>
<div id="dashboard">
<h:form id="form" prependId="false">
<h:outputText value="Welkom #{loginBean.username}"/>
<p:accordionPanel autoHeight="true" effect="bounceslide">
<p:tab title="My studies">
<p:dataTable var="study" value="#{studyBean.studiesByUser}" id="studyTable"
emptyMessage="No studies found for given user" paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15" rowSelectListener="#{studyBean.onRowSelect}"
selectionMode="single">
<p:column headerText="StartDate" sortBy="#{study.startDate}"
filterBy="#{study.startDate}"
filterMatchMode="contains" style="width: 100px;">
<h:outputText value="#{study.startDate}">
<f:convertDateTime pattern="dd/MM/yyyy" type="date" timeZone="CET"/>
</h:outputText>
</p:column>
<p:column headerText="EndDate" sortBy="#{study.endDate}"
filterBy="#{study.endDate}}"
filterMatchMode="contains" style="width: 100px;">
<h:outputText value="#{study.endDate}">
<f:convertDateTime pattern="dd/MM/yyyy" type="date" timeZone="CET"/>
</h:outputText>
</p:column>
<p:column headerText="School" sortBy="#{study.school}" filterBy="#{study.school}}"
filterMatchMode="contains" style="width: 100px;">
<h:outputText value="#{study.school}"/>
</p:column>
<p:column headerText="Specialization" sortBy="#{study.specialization}"
filterBy="#{study.specialization}}" filterMatchMode="contains"
style="width: 100px;">
<h:outputText value="#{study.specialization}"/>
</p:column>
<p:column headerText="Remarks" sortBy="#{study.remarks}"
filterBy="#{study.remarks}}"
filterMatchMode="contains" style="width: 100px;">
<h:outputText value="#{study.remarks}"/>
</p:column>
</p:dataTable>
<h:commandButton id="btnAddStudy" title="Add Study" value="Add Study">
<f:ajax render=":content" execute="form" listener="# {studyBean.navigate}"/>
<f:param name="action" value="add"/>
</h:commandButton>
</p:tab>
</p:accordionPanel>
</h:form>
So as you can see is my <h:panelGroup> outside my form.
This is the included page (as example)
<h:body>
<ui:composition template="../template/template.xhtml">
<ui:define name="body">
<f:view contentType="text/html">
<ui:composition>
<h:form id="studyForm" prependId="false">
<p:messages />
<h:message for="startDate"/>
<h:message for="endDate"/>
<h:message for="school"/>
<h:message for="diploma1"/>
<h:message for="diploma2"/>
<h:message for="diploma3"/>
<h:message for="specialization1"/>
<h:message for="specialization2"/>
<h:message for="specialization3"/>
<h:message for="remarks1"/>
<h:message for="remarks2"/>
<h:message for="remarks3"/>
<h:outputText class="label" value="Start date: "/>
<h:inputText id="startDate" styleClass="inputtext validate[required,custom[date]]"
value="#{studyBean.startDate}">
<f:convertDateTime pattern="dd/MM/yyyy" timeZone="CET"/>
</h:inputText>
<h:outputText class="label" value="End date: "/>
<h:inputText id="endDate" styleClass="inputtext validate[required,custom[date]]"
value="#{studyBean.endDate}">
<f:convertDateTime pattern="dd/MM/yyyy" timeZone="CET"/>
</h:inputText>
<h:outputText class="label" value="school: "/>
<h:inputText id="school" styleClass="inputtext validate[required, maxSize[5]]"
value="#{studyBean.school}"/>
<h:outputText class="label" value="Specialization: "/>
<h:inputText id="specialization1" styleClass="inputtext validate[maxSize[50]]"
value="#{studyBean.specialization[0]}"/>
<h:inputText id="specialization2" styleClass="inputtext validate[maxSize[50]]"
value="#{studyBean.specialization[1]}"/>
<h:inputText id="specialization3" styleClass="inputtext validate[maxSize[50]]"
value="#{studyBean.specialization[2]}"/>
<h:outputText class="label" value="Diploma: "/>
<h:inputText id="diploma1" styleClass="inputtext validate[maxSize[50]]"
value="#{studyBean.diploma[0]}"/>
<h:inputText id="diploma2" styleClass="inputtext validate[maxSize[50]]"
value="#{studyBean.diploma[1]}"/>
<h:inputText id="diploma3" styleClass="inputtext validate[maxSize[50]]"
value="#{studyBean.diploma[2]}"/>
<h:outputText class="label" value="remarks: "/>
<h:inputText id="remarks1" styleClass="inputtext validate[maxSize[200]]"
value="#{studyBean.remarks[0]}"/>
<h:inputText id="remarks2" styleClass="inputtext validate[maxSize[200]]"
value="#{studyBean.remarks[1]}"/>
<h:inputText id="remarks3" styleClass="inputtext validate[maxSize[200]]"
value="#{studyBean.remarks[2]}"/>
<h:commandButton action="cancel" value="cancel" immediate="true"/>
<p:commandButton id="btnAddStudyDetail" value="add study" actionListener="#{studyBean.addStudy}"
update="studyTable" oncomplete="clearAddStudy()"/>
</h:form>
</ui:composition>
</f:view>
</ui:define>
</ui:composition>
</h:body>
Managed Bean #RequestScoped
#ManagedBean
#RequestScoped
public class StudyBean {
public String navigate() {
FacesContext facesContext = FacesContext.getCurrentInstance();
try {
action = (((HttpServletRequest) facesContext.getExternalContext().getRequest()).getParameter("action"));
if (action.equals("add")) {
//vull de velden
includePage = "studyDetail.xhtml";
}
facesContext = FacesContext.getCurrentInstance();
UIViewRoot root = facesContext.getViewRoot();
UIComponent form = root.findComponent("form");
dataTable = form.findComponent("studyTable");
System.out.println(dataTable);
System.out.println(root);
} catch (Exception e) {
facesContext.addMessage("form", new FacesMessage("You must select a study."));
}
return null;
}
}
Thanks in advance.
UPDATE
Now I am able to dynamically load the page in my <ui:include> but I have another problem now, when the page is loaded and I want to click on my button in the loaded page the action to which it is bound doesn't execute. So I don't get into my backing bean, I already tried to put the scope of my bean to #ViewScoped but no success.
Please help me as I am getting desperate.

Resources