Passing <p:inputText> values to Bean using ajax - ajax

I am having the h:inputText which having a text and by ajax request how can i send it's values to bean class and the values will be validated in further action begin at bean class ..
view page code is
<h:form>
<p:panel id="panel" header="Login Panel" style="margin:0 auto;width:350px;margin-top:15%;">
<p:panelGrid columns="3" id="pgrid1" styleClass="theme" >
<p:outputLabel value="User Name:" />
<p:inputText id="name" value="#{loginBean.name}" required="true" requiredMessage="Name is required">
<f:ajax event="blur" render="label" listener="loginBean.validateName" ></f:ajax>
<!--Here the ajax event working properly but how can i get the inputText value when ajax event is invoked-->
</p:inputText>
<p:message for="name" style="color: red;" />
</p:panelGrid>
<p:commandButton type="Submit" value="Submit" action="#{loginBean.validate}" update="pgrid1" />
</p:panel>
My Bean class Code is :
public void validateName(AjaxBehaviorEvent e)
{
//Here i need inputText value..how can i handle this task..!!
}

JSF has already set the #{loginBean.name} value at that moment. Just access it directly.
public void validateName(AjaxBehaviorEvent e)
{
System.out.println(name); // Look, JSF has already set it.
// ...
}
You've by the way an EL syntax error in <f:ajax listener> which causes the listener method never to be invoked, but I'll bet it to be just carelessness during preparing the question as you mentioned that it is "working properly". In the future questions, please edit code in the real development environment and copypaste real working code instead of blindly editing the code in the question editor.

Related

Ajax request and attributes

I am trying this tutorial which describes how to set attributes into server call and how to analyse the attributes on backing bean;
<h:commandButton id="submit"
actionListener="#{userData.attributeListener}" action="result">
<f:attribute name="value" value="Show Message" />
<f:attribute name="username" value="JSF 2.0 User" />
</h:commandButton>
I googled a lot but most examples show how to set attrs for synch-ed calls not the asynch-ed ones :S So my question is ... how to send attributes on server if that would be the ajax call and how to get them on backing bean (see suggestion A code snippet)?
suggestion A :
<h:commandButton id="submit"
actionListener="#{userData.attributeListener}" action="result">
<f:ajax>
<f:attribute/>? how to
</f:ajax>
</h:commandButton>
and if there is a good tutorial concerning to this question please do share the link :)
Thanks
OK I just wrote a test which sets attributes out the ajax block as :
<h:commandButton id="submit"
actionListener="#{userData.callWithAttributes}" action="result">
<f:attribute name="a" value="#{testa}"/>
<f:attribute name="b" value="#{testb}"/>
<f:ajax .../>
</h:commandButton>
...and on the backing bean
...
public void callWithAttributes(ActionEvent e){
String a=(String) e.getComponent().getAttributes().get("a");
...
}
...
Seems like it's working fine :) So attributes should be placed into event-making component block - the h:commandButton in this particular case...
To set two properties in backing bean you can use f:setPropertyActionListener
<h:commandButton action="#{bean.method}">
<f:setPropertyActionListener value="#{testA}" target="#{bean.valueA}/>
<f:setPropertyActionListener value="#{testB}" target="#{bean.valueB}/>
</h:commandButton>
or with EL method argument support:
<h:commandButton action="#{bean.method(testA, testB)}"/>

jsf f:ajax tag corrupts request

Am using Spring with JSF
I have a view scoped bean which contains a function, the xhtml file contains a dropdown menu which on value change updates some message to the user and a button which calls the function. When I change the dropdown and click the button, the function is not called
Upon removing the tag
<f:ajax event="blur" render="type_message" />, the function is called and it worked fine
it same problem as in Primefaces Commandbutton not working after an update made by select box
#Scope("view")
#Component("propertyBean")
public class PropertyBean implements Serializable {
...
public String update() {
...
return"/page.xhtml";
}
}
xhtml
<h:selectOneMenu id="type" required="true"
requiredMessage="#{msgBean.getRequired()}"
styleClass="btn btn-white dropdown-toggle" style="width:100%"
value="#{propertyBean.property.propertyDetails.type}"
converter="#{typeConverter}">
<f:selectItem itemValue="#{null}" itemLabel="choose item"
noSelectionOption="true" />
<f:selectItems value="#{dataBean.availableTypes}"
var="typeObj" itemValue="#{typeObj}"
itemLabel="#{typeObj.type}"/>
<f:ajax event="blur" render="type_message" />
</h:selectOneMenu>
<h:message id="type_message" for="type"
infoClass="help-block" errorClass="help-block error" />
<h:commandButton id="update" value="save"
onclick="if( validate('submitForm')==true){ updateProperty();} else{ return false;}"
action="#{propertyBean.update}"
class="btn btn-green btn-lg arabic"
rendered="#{propertyBean.isNew == false}">
<f:param name="propertyId" value="#{propertyBean.property.id}">
</f:param>
</h:commandButton>
on changing <f:ajax> to <p:ajax> it worked, any explanations

Ajax validation, different Messages

Hi guys I have a real problem with my validation in JSF. I want to validate a Mail-Address if it's already used and the correct mail format. Here are the picture how it should look.
https://www.dropbox.com/s/bs9nshmuurauc2e/Unbenannt.JPG
I hope can understand the problem. I don't now how I can implement it.
Can I set different messages for different events?
I use primefaces 3.5 and jsf 2.1
<p:row>
<p:column style="width:400px">
<h:outputLabel for="email" styleClass="outputRight" value="#{msg['regi_mail']}" />
</p:column>
<p:column style="width:350px">
<p:inputText style="width:350px" requiredMessage="#{msg['regi_mail_valid']}" validatorMessage="#{msg['regi_mail_valid']}" id="email" value="#{regiBean.user.EMAIL}" required="true">
<f:validateRegex pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*#[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
<f:ajax event="blur" render="format user" />
</p:inputText>
</p:column>
<p:column style="width:410px">
<h:panelGroup id="mail" class="fa fa-question-circle fa-2x" />
<p:overlayPanel for="mail" showEvent="mouseover" hideEvent="mouseout" hideEffect="fade">
<p:panel>
TEXTTEXTTEXT
</p:panel>
</p:overlayPanel>
<p:message id="format" for="email" />
</p:column>
</p:row>
<p:row>
<p:column style="width:400px">
<h:outputLabel styleClass="outputRight" value="Username" />
</p:column>
<p:column style="width:350px">
<h:outputLabel id="user" style="color: green;" value="#{regiBean.user.EMAIL}" />
</p:column>
<p:column>
<h:panelGroup id="us" class="fa fa-minus-square fa-2x" />
<h:panelGroup/>
</p:column>
</p:row>
I've done something like this but front end only different.
XHTML File
The Bean Code
I hope you will get some help from this.
This may be a little late, I see the question was asked in Feb already. However, seems this would be a case where you should rather supply a custom validator. Here is my suggestion:
Remove the validatorMessage attribute from you id="email" element. Also remove the f:validateRegex validator in that input element.
Create a custom validator. It should:
Have a #ManagedBean (or similar) annotation (so that the EL in your JSF page can reference it)
implement javax.faces.validator.Validator
override the validate() method. In it you do your validations, e.g. check your regexp as well as query the database for existing addresses via e.g. JPA (or an EJB business method). If validation fails, you throw a javax.faces.validator.ValidatorException, that is constructed with a javax.faces.application.FacesMessage instance containing the relevant error message (there are various constructors, find an applicable one).
If you do not want to code something in this validator, but "pass it in" from the JSF page, you could do that via attribute passing. Useful if you e.g. would want to pass in your (i18z'ed) error message, values of other fields on the form, etc. etc. The only things available inside the validate() method by default is the FacesContext, the UIComponent, and the value that is validated. (See example below.)
Modify your JSF similar to the example below.
Example - Validator class:
#ManagedBean public class MyEmailValidator implements Validator {
#EJB UserEJBLocal userEJB; // supposing you want to use a method in there to get list of e-mail addresses
private static final String REGEXP = "^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*#[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$";
#Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
if (! Pattern.matches(REGEXP, value.toString())) {
throw new ValidatorException(new FacesMessage(component.getAttributes().get("formatMsg")));
}
List existingAddresses = userEJB.getAllAddresses(); // or whatever method your are using to obtain current addresses, e.g. JPA.
if (existingAddresses.contains(value.toString()) {
throw new ValidatorException(new FacesMessage(
FacesMessage.SEVERITY_ERROR,
"The address already exists." // could also be passed in as attribute, etc.
));
}
}
}
Example - JSF snippet:
<p:inputText id="email" value="#{regiBean.user.EMAIL}"
requiredMessage="#{msg['regi_mail_valid']}" required="true"
>
<f:validator binding="${myEmailValidator}" />
<f:attribute name="formatMsg" value="#{msg['regi_mail_valid']}" />
: <!-- other attributes, if needed -->
<f:ajax event="blur" render="email-msg user" />
</p:inputText>
:
<p:message id="email-msg" for="email" />
Well, the above example may not be complete, but might point you in the right direction.
OK, so maybe you want to check the current row's e-mail against the e-mails in the other rows? You are a bit out of luck... The only way I can think of is to somehow gather them all into a list, which you can pass via another attribute to the validator. Not very easy with a dynamic table... You might want to rethink your process.

Open PrimeFaces Dialog located in another .xhtml file

I have a number of questions that are related to each other so the title of question may not be appropriate. Sorry for this.
I want to have a p:inputText and p:commandButton in a p:dialog such that when the user presses that button or presses enter key the value entered in the
p:inputText will be saved in the database. To do this I followed this example http://www.primefaces.org/showcase/ui/dialogForm.jsf and it worked fine when I tried it in a seperate .xhtml file in which there were no other dialogs or command buttons.
<h:body>
<h:form id="form">
<p:commandButton id="showDialogButton" type="button" value="Show" onclick="PF('dlg').show()" />
<p:dialog header="Enter FirstName" widgetVar="dlg" resizable="false">
<h:panelGrid columns="2" style="margin-bottom:10px">
<h:outputLabel for="firstname" value="Firstname:" />
<p:inputText id="firstname" value="#{subjectController.attributeValue}" />
</h:panelGrid>
<p:commandButton id="submitButton" value="Submit" update=":form:display :form:firstname" action="#{subjectController.saveUpdateSubjectAttributeValue}" oncomplete="PF('dlg').hide();"/>
<p:defaultCommand target="submitButton"></p:defaultCommand>
</p:dialog>
<p:outputPanel id="display" style="display:block;margin-top:10px;">
<h:outputText id="name" value="Hello #{subjectController.attributeValue}" rendered="#{not empty subjectController.attributeValue}"/>
</p:outputPanel>
</h:form>
</h:body>
The .xhtml file that I originally have contains a number of other dialogs and command buttons. When i used the same code in that file it does not work properly. By not working properly I mean to say that when enter key or submit button is pressed the value entered by the user is not set in the corresponding setter of the inputText in the managed bean. To call the setter before pressing the enter key or button I need to use p:ajax inside p:inputText tag. I tried to use p:ajax events such as "mouseout", "blur", "change" etc. They work for the submit button but not for the enter key. Then I tried "keypress" and "keyup" etc. They worked for both but the setter for the value in the p:inputText was called on each key press which was not desired.
My first question:
If the sample code is working fine in a separate file why doesn't it work when I have other dialogs or commandbuttons in the same file. In both the cases I am using the same managed bean. What is the difference?
Assuming that the problem may be caused using more than one dialogs in the same file, I thought of declaring these dialogs in separate files such that I have
A.xhtml , B.xhtml, C.xhtml pages which contain the actual content and whenever I need to open a dialog the required dialog is located in file such as dialog.xhtml. Being a beginner in JSF, Primefaces and Ajax I was confused about how to do this. Searching on the internet I found this post relevant PrimeFaces dialog lazy loading (dynamic="true") does not work?. But in this case, p:dialog is located on the same page but the content contained in this dialog is located in another file which is included using ui:include. I tried this but it shows the same behavior.
My Second Question:
Is there any way to programmatically open a dialog from another file e.g. if I have a p:commandButton in A.xhtml and p:dialog in the same file I can do this using
<p:commandButton id="submitButton" value="Submit" update=":form:display :form:firstname" action="#{subjectController.saveUpdateSubjectAttributeValue}" oncomplete="PF('dlg').hide();"/>
and in the corresponding subjectController I have
saveUpdateSubjectAttributeValue(){
RequestContext context = RequestContext.getCurrentInstance();
context.openDialog("openDialog");
// or
context.execute("openDialog");
}
But what if the "openDialog" is located in B.xhtml?
What I understand, I can use enclose p:dialog in a ui:composition (in B.xhtml) and and use ui:include in A.xhtml. But I am confused in how and where to call openDialog.open() or openDialog.hide()?
I've tried to replicate the behavior you posted here and I believe that the cause is probably somewhere else as mentioned by Yipitalp.
Anyway, here are the sample code I used that might do what you expect (Primefaces 4):
The Managed Bean
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.context.RequestContext;
#ManagedBean
#ViewScoped
public class DialogBean implements Serializable {
private String attribute1;
private String attribute2;
private String attribute3;
private String dlg;
public void openDialog() {
RequestContext context = RequestContext.getCurrentInstance();
context.execute("PF('" + dlg + "').show()");
}
public String getAttribute1() {
return attribute1;
}
public void setAttribute1(String attribute1) {
this.attribute1 = attribute1;
}
public String getAttribute2() {
return attribute2;
}
public void setAttribute2(String attribute2) {
this.attribute2 = attribute2;
}
public String getAttribute3() {
return attribute3;
}
public void setAttribute3(String attribute3) {
this.attribute3 = attribute3;
}
public String getDlg() {
return dlg;
}
public void setDlg(String dlg) {
this.dlg = dlg;
}
}
The view
Note that I use a different form for every dialog in the view.
<h:form>
<h:panelGrid columns="2" style="margin-bottom:10px">
<h:outputLabel for="dlg" value="Dlg:" />
<p:selectOneMenu id="dlg" value="#{dialogBean.dlg}" >
<f:selectItem itemLabel="dlg1" itemValue="dlg1" />
<f:selectItem itemLabel="dlg2" itemValue="dlg2" />
<f:selectItem itemLabel="dlg3" itemValue="dlg3" />
</p:selectOneMenu>
</h:panelGrid>
<p:commandButton id="submitButton" value="Submit" action="#{dialogBean.openDialog}"/>
<p:defaultCommand target="submitButton" />
</h:form>
<p:button id="showDialogButton1" value="Show 1" onclick="PF('dlg1').show();
return false;" />
<p:button id="showDialogButton2" value="Show 2" onclick="PF('dlg2').show();
return false;" />
<p:button id="showDialogButton3" value="Show 3" onclick="PF('dlg3').show();
return false;" />
<br />
<p:dialog header="Enter FirstName" widgetVar="dlg1" resizable="false">
<h:form>
<h:panelGrid columns="2" style="margin-bottom:10px">
<h:outputLabel for="firstname" value="Firstname:" />
<p:inputText id="firstname" value="#{dialogBean.attribute1}" />
</h:panelGrid>
<p:commandButton id="submitButton" value="Submit" oncomplete="PF('dlg1').hide();"/>
<p:defaultCommand target="submitButton" />
</h:form>
</p:dialog>
<p:dialog header="Enter FirstName" widgetVar="dlg2" resizable="false">
<h:form>
<h:panelGrid columns="2" style="margin-bottom:10px">
<h:outputLabel for="firstname" value="Firstname:" />
<p:inputText id="firstname" value="#{dialogBean.attribute2}" />
</h:panelGrid>
<p:commandButton id="submitButton" value="Submit" oncomplete="PF('dlg2').hide();"/>
<p:defaultCommand target="submitButton" />
</h:form>
</p:dialog>
<p:dialog header="Enter FirstName" widgetVar="dlg3" resizable="false">
<h:form>
<h:panelGrid columns="2" style="margin-bottom:10px">
<h:outputLabel for="firstname" value="Firstname:" />
<p:inputText id="firstname" value="#{dialogBean.attribute3}" />
</h:panelGrid>
<p:commandButton id="submitButton" value="Submit" oncomplete="PF('dlg3').hide();"/>
<p:defaultCommand target="submitButton" />
</h:form>
</p:dialog>
<p:outputPanel autoUpdate="true" style="border: 1px solid black; margin-top:10px;">
Value 1:
<h:outputText id="v1" value="#{dialogBean.attribute1}" />
<br />
Value 2:
<h:outputText id="v2" value="#{dialogBean.attribute2}" />
<br />
Value 3:
<h:outputText id="v3" value="#{dialogBean.attribute3}" />
</p:outputPanel>
I hope that will give you some clue!
I was able to solve major part of my problems using DialogFramework. I have a Menu.xhtml page, it contains p:tieredMenu in p:layoutUnit with position="north" using which I select which page to open. Depending on the selection, the p:layoutUnit with position="center" includes that page using ui:include. The Menu.xhtml page contains a h:form with id="form" inside h:body and everything else is placed inside this h:form. There are a number of pages that can be included inside the <p:layoutUnit position="center"> depending upon the selection. One of them is Person.xhtml(containing everything enclosed inside a ui:composition ). It contains a p:fieldset. Inside p:fieldset there are 3 p:dataTable. Outside this p:fieldset I have placed 3 p:contextMenu one for each of those datatables. Inside one of those p:contextMenu I have placed
<p:menuitem value="Update" actionListener="#{controller.updateAttributeValue}" />
and the corresponding function contains
public void updateAttributeValue(){
System.out.println("update attribute value");
RequestContext context = RequestContext.getCurrentInstance();
context.openDialog("selectCar2");
this.attributeValue = null;
}
selectCar2.xhtml contains the following code
<h:body>
<h:form>
<h:panelGrid id="updateAttributeValuePanel" columns="2" style="margin-bottom:10px">
<h:outputLabel value="Attribute Value " />
<p:inputText id="attributeValue" value="#{controller.attributeValue}" required="true" />
</h:panelGrid>
<p:commandButton id="saveUpdateAttributeValue" value="Submit" actionListener="#{controller.saveUpdateAttributeValue}"
/>
<p:commandButton id="cancelUpdateAttributeValue" value="Cancel "
action="#{controller.cancelUpdateAttributeValue}"
/>
<p:defaultCommand target="saveUpdateAttributeValue" />
</h:form>
</h:body>
The corresponding save function is as follows
public void saveUpdateAttributeValue(){
RequestContext context = RequestContext.getCurrentInstance();
System.out.println("this.attributevalue = " + this.attributeValue);
////save value in database
this.attributeValue = null;
context.update(":form:resourceAttributeValueDataTable");
//also tried context.update("resourceAttributeValueDataTable");
context.closeDialog(this.attributeValue);
}
and
public void cancelUpdateAttributeValue(){
RequestContext context = RequestContext.getCurrentInstance();
context.closeDialog(this.attributeValue);
System.out.println("cancel update attribute value");
this.attributeValue = null;
System.out.println("this.attributevalue = " + this.attributeValue);
}
The dialog opens and the value is successfully saved in the database. The only problem now is that the corresponding datatable is not updated and I need to refresh the page to see the updated value. previously my dialog was also in the same page outside the p:fieldset and I was not using h:form inside dialog so I was updating the datatable as
<p:commandButton id="saveUpdateAttributeValue" value="Submit" actionListener="#{controller.saveUpdateAttributeValue}"
update = ":form:attributeValueDataTable "/>
But now they are in two different files and two different forms so I am not sure how to update in this case? I have tried to use
context.update(":form:resourceAttributeValueDataTable");
//or
context.update("resourceAttributeValueDataTable");
but the datatable is not updated. Any help will be highly appreciated.

JSF : How to refresh required field in ajax request

Ok, here you are the core problem.
The page. I have two required "input text".
A command button that changes the bean value and reRenderes the "job" object.
<a4j:form id="pervForm">
SURNAME:<h:inputText id="surname" label="Surname" value="#{prevManager.surname}" required="true" />
<br/>
JOB:<h:inputText value="#{prevManager.job}" id="job" maxlength="10" size="10" label="#{msg.common_label_job}" required="true" />
<br/>
<a4j:commandButton value="Set job to Programmer" ajaxSingle="true" reRender="job">
<a4j:actionparam name="jVal" value="Programmer" assignTo="#{prevManager.job}"/>
</a4j:commandButton>
<h:commandButton id="save" value="save" action="save" class="HATSBUTTON"/>
</a4j:form>
Here the simple manager:
public class PrevManager
{
private String surname;
private String job;
public String getSurname()
{
return surname;
}
public void setSurname(String surname)
{
this.surname = surname;
}
public String getJob()
{
return job;
}
public void setJob(String job)
{
this.job = job;
}
public String save()
{
//do something
}
}
Let's do this:
Write something on the Job input text (such as "teacher").
Leave empty the surname.
Save.
Validation error appears (surname is mandatory).
Press "Set job to Programmer": nothing happens.
Checking the bean value, I discovered that it is correctly updated, indeed the component on the page is not updated!
Well, according to the JBoss Docs I found:
Ajax region is a key ajax component.
It limits the part of the component
tree to be processed on the server
side when ajax request comes.
Processing means invocation during
Decode, Validation and Model Update
phase. Most common reasons to use a
region are:
-avoiding the aborting of the JSF lifecycle processing during the
validation of other form input
unnecessary for given ajax request;
-defining the different strategies when events will be delivered
(immediate="true/false")
-showing an individual indicator of an ajax status
-increasing the performance of the rendering processing
(selfRendered="true/false",
renderRegionOnly="true/false")
The following two examples show the
situation when a validation error does
not allow to process an ajax input.
Type the name. The outputText
component should reappear after you.
However, in the first case, this
activity will be aborted because of
the other field with required="true".
You will see only the error message
while the "Job" field is empty.
Here you are the example:
<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:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<style>
.outergridvalidationcolumn {
padding: 0px 30px 10px 0px;
}
</style>
<a4j:outputPanel ajaxRendered="true">
<h:messages style="color:red" />
</a4j:outputPanel>
<h:panelGrid columns="2" columnClasses="outergridvalidationcolumn">
<h:form id="form1">
<h:panelGrid columns="2">
<h:outputText value="Name" />
<h:inputText value="#{userBean.name}">
<a4j:support event="onkeyup" reRender="outname" />
</h:inputText>
<h:outputText value="Job" />
<h:inputText required="true" id="job2" value="#{userBean.job}" />
</h:panelGrid>
</h:form>
<h:form id="form2">
<h:panelGrid columns="2">
<h:outputText value="Name" />
<a4j:region>
<h:inputText value="#{userBean.name}">
<a4j:support event="onkeyup" reRender="outname" />
</h:inputText>
</a4j:region>
<h:outputText value="Job" />
<h:inputText required="true" id="job1" value="#{userBean.job}" />
</h:panelGrid>
</h:form>
</h:panelGrid>
<h:outputText id="outname" style="font-weight:bold" value="Typed Name: #{userBean.name}" />
<br />
</ui:composition>
Form1: the behaviour is incorrect. I need to fill the job and then the name.
Form2: the behaviour is correct. I do not need to fill the job to see the correct value.
Unfortunately using Ajax region does not help (indeed I used it in a bad way ...) because my fields are both REQUIRED. That's the main different.
Any idea?
Many thanks.
This problem is also identified in JSF 2 and explained in detail in this related answer: How can I populate a text field using PrimeFaces AJAX after validation errors occur?
Summarized, the answer is that you need to clear the state of the EditableValueHolder component when it's about to be ajax-rendered, but which isn't included in the ajax-execute, by calling the methods setValue(null), setSubmittedValue(null), setLocalValueSet(false), setValid(true). Note: in JSF 2 you would have used the convenience method resetValue() instead.
Given that your "job" input field has the client ID prevForm:job, here's how you could clear it inside the action listener method associated with the "Set job to programmer" button:
UIInput input = (UIInput) context.getViewRoot().findComponent("prevForm:job");
input.setValue(null);
input.setSubmittedValue(null);
input.setLocalValueSet(false);
input.setValid(true);
Using a4j:actionparam will set the value, but will not help you bypass validation in this case. Validation happens on the component (not the bean property). So, when you submit, the component value is still empty. Hope this helps.
When you click "Set job to Programmer" nothing happens because you are not reRendering your message component. If you do, you'll be able to see the validation message.
You need to reRender the message because its a <a4j:commandButton/>, not a simple <h:commandButton/>
Try to use the prop. immediate in "Set job to Programmer" button and check if it will update the field.
<a4j:commandButton value="Set job to Programmer" ajaxSingle="true" reRender="job" immediate="true">
<a4j:actionparam name="jVal" value="Programmer" assignTo="#{prevManager.job}"/>
</a4j:commandButton>
*I dont think "ajaxSingle" necessary here..
Maybe you can get a new problem.. using immediate, the bean value will be not updated (MAYBE!). If it happens, make a bean method which sets manually the bean value.
Otherwise, if the bean value was updated and the field still empty, try to put the "job" field into a <a4j:outputPanel/> and reRender the outputPanel.
<a4j:outputPanel id="myPanel">
<h:inputText value="#{prevManager.job}" id="job" maxlength="10" size="10" label="#{msg.common_label_job}" required="true" />
</a4j:outputPanel/>
<a4j:commandButton value="Set job to Programmer" reRender="myPanel" immediate="true">
<a4j:actionparam name="jVal" value="Programmer" assignTo="#{prevManager.job}"/>
</a4j:commandButton>
More info about <a4j:outputPanel/> here.

Resources