jsf focus inputtext field after form rerenders with values onblur - java

After onbluring an input text field inside my form , I'm rerendering the form with the new values.
In this case the field loses it's focus, I want the input that was after the one I blured out from to be focused. is there an after render event, or somthing that will give the option to choose the cell i want to focus on?
Thank's In Advance.

I'm not sure this would work but you can try the following:
<h:form id="myForm">
<h:inputText id="my1stInput" >
<a4j:ajax event="blur" render="myForm" oncomplete="document.getElementById('myForm:my2ndInput').focus()" />
</h:inputText>
<h:inputText id="my2ndInput" />
</h:form>

Related

form field in jsp not change java variable

I can't change the data information in my jsp page when I submit the form and call a java function(When the button is pressed).
This is a peace of code used in my .jsp form field:
...
<h:form>
<h:panelGrid columns="3">
<h:outputLabel for="contactName" value="#{msj.contactName}"/>
<h:inputText id="contactName" value="#{CustodiaBean.name}" required="true">
<f:validator validatorId = "TextValidator" />
</h:inputText>
<h:message for="contactName" styleClass="errorMessage" style="color:red"/>
<h:outputLabel for="contactLastName" value="#{msj.contactLastName}"/>
<h:inputText id="contactLastName" value="#{CustodiaBean.last_name}" required="true" >
<f:validator validatorId = "TextValidator" />
</h:inputText>
<h:message for="contactLastName" styleClass="errorMessage" style="color:red"/>
</h:panelGrid>
<div id="button">
<h:commandLink styleClass="hoveringLink3doubleGreen" action="#{CustodiaBean.updateAccount}">
<h:outputText id="save_button" value="#{msj.save_changes}"/>
</h:commandLink>
<h:commandLink styleClass="hoveringLink3double" action="myAccountCustodia">
<h:outputText id="cancel_button" value="#{msj.cancel}"/>
</h:commandLink>
</div>
</h:form>
...
This is the same piece of code used in other pages like login and register user.
The form fields get the current values in "CustodiaBean", but i try to change the value in the form and when I press the button to check the value(call a function in "CustodiaBean"), I always get the previous value (The new form value is not changed in my class "CustodiaBean").
I'm using a tomcat server and eclipse.
Is necesary to force the field to be bloqued and save the changes when the button is pressed??
I don't know why this is happen. Can anyone help me or give me some advice??
Thanks a lot in advance
Does h:inputText etc also has a property name? Try to see what html is generated. It may be possible that your data is not getting submitted properly. Any HTML form directly submit feilds which are non disabled with the name property of each field. IF id is present and not name, it wont be submitted correctly. Try debugging at browser level or via some firefox plugin like tamper data.
Hope it helps

Primefaces datatable cell editing doesn't update

I have a primefaces datatable with cell editing which is toggled on a boolean variable in the view.
I have three issues:
In edit mode, I change a value and I click the save button on the page it doesn't keep the new value, If I click anywhere else first on the page then click save it will keep the value. I need it to keep the value if you click save first.
If I edit a cell which is an input text and I click out the field now is a output text until I click in there again. I want the field to look like a input text while in edit mode.
When the save button is clicked the backing method sets the editable boolean to false, and the rest of the page obeys, and the dataTable looks like it obeyed but if you click a cell it will let you edit it.
Here is the code:
<p:dataTable value="#{view.LineItems}" var="lineItem" rowKey="#{lineItem.lineItemId}"
resizableColumns="false" editable="#{view.editable}" editMode="cell"
editingRow="#{view.editable}" id="requestLineItemsTable">
<p:ajax event="cellEdit" listener="#{view.cellEdited}" immediate="true" update="#this" />
<p:column styleClass="centerColumnData" headerText="Item Name" style="width: 140px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{lineItem.title}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{lineItem.title}"/>
</f:facet>
</p:cellEditor>
</p:column> ...
and this is the back end (not doing anything with this yet)
public void cellEdited(CellEditEvent event)
{
Object oldValue = event.getOldValue();
}
and here is the save and edit buttons on the same .xhtml page as datatable
<p:commandLink process="#this"
action="#{view.changeModeToEdit}"
update="#form"
rendered="#{!view.editMode">
<h:graphicImage library="images" name="edit20.png" title="#{__Common.edit}"
style="height: 15px; width: 15px;"/>
</p:commandLink>
<components:linkWithSpinner linkStyle="margin-right: 20px;" loadingImageStyle="margin-right: 20px;"
linkStyleClass="activeButton saveButtonRequestDetails" loadingImageStyleClass="saveButtonRequestDetails"
linkText="#{__CommonButton.save}"
process="#form" update="#form"
actionMethod="#{view.updateRequest()}"/>
view.updateRequest() sets the editable to false. I am using Primefaces 4.0
So I figured out a way around these issues. I was focused on using the built in edit table , but you can just have a normal datatable and the columns can contain input text fields. Then you don't have to worry about most of the issues in my question above. If you need to switch between edit and non-edit view then I still don't know how to fully fix it except have two datatables in your file with render tags, but then you are duplicating the table one with input text fields and one with output text fields, and that is not the best way to do it.

How to show a value from database in input text?

I am trying to show a value from the database in a input text to update it. so when I click on the column the program show a window with all the values but as an inputtext so the user can't update the values.
I am using PrimeFace 4, jsf and mysql as a database
<i>
<h:panelGrid id="display" columns="2" cellpadding="4">
<h:outputText value="ID:" />
<h:outputText value="#{usersBean.selectUser.idUtilisateur}"
style="font-weight:bold" />
<h:outputText value="Nom:" />
<h:inputText value="#{usersBean.selectUser.nomUtilisateur}"
style="font-weight:bold" />
<h:outputText value="Prenom" />
<h:inputText value="#{usersBean.selectUser.prenomUtilisateur}"
style="font-weight:bold" />
<h:outputText value="Indentifiant" />
<h:inputText value="#{usersBean.selectUser.identifiUtilisateur}"
style="font-weight:bold" />
</h:panelGrid>
<i/>
Any input field should be inside a form (h:form will do) to be processed. You could omit this in case you just want to output the data. But in this case it would be more "correct" to use "output" elements for this task.
Since you use PrimeFaces I would highly recommend using p:inputText (http://www.primefaces.org/showcase/ui/inputText.jsf). It has all the attributes of h:inputText but is more compatible with PF processors.
To show any value inside an inputText you just have to initialize it in the provided managed bean. And of course, if you use partial submit approach don't forget to update the element/container you're trying to show values at.

How to persist from multiple forms with one button?

I have two forms, an one button.
<h:form>
<h:outputLabel value="Form Name: *" />
<p:inputText required="true" value="#{currentTemplate.name}" />
</h:form>
and one button in another form.
<h:form id="orderListForm">
<p:commandButton value="Submit"
action="#{orderListBean.callPersist}" style="margin-top:5px"
id="btnCitySubmit" />
</h:form>
I want to save the value from the first form with the second.
I really appreciate your answer!
Do you want to execute all inputs in both forms? Then process="#all" attribute of <p:commandButton> is for you. It will process all inputs within a page.
Alternatively, you can specify ids of components to be processed, like process="#form :another-form", if to-be-updated form has id="another-form" specified.

Can't persist my input text

I have an input text area, inside a panel grid. This panel grid is only rendered when a check box is ticked. I'm using a value change listener to listen to the check box to render the text area. This rendering mechanism works, but the trouble is that I can't retrieve the value the user inputs in the text area. It always returns null. Any help appreciated.
// if box is checked, input text area is rendered
public void showURL(ValueChangeEvent event) {
FacesContext context = FacesContext.getCurrentInstance();
boolean value = (Boolean) event.getNewValue();
setRenderURL(value);
context.renderResponse();
}
<h:panelGrid columns="2" >
<h:outputLabel value="Is position vacant?" />
<h:selectBooleanCheckbox valueChangeListener="#{formBean.showURL}"
onclick="submit()"
immediate="true" />
</h:panelGrid>
<h:panelGrid columns="2" rendered="#{formBean.renderURL}" >
<h:panelGroup>
<h:outputLabel value="Link: "/>
// trouble here: getURL always returns null
<h:inputText size="60" value="#{formBean.URL}" />
</h:panelGroup>
</h:panelGrid>
Add
<h:inputHidden value="#{formBean.renderURL}" />
to the same form so that the condition for the rendered attribute is retained during the request wherein input components are processed. JSF namely won't validate/convert/update an input component whenever the rendered attribute of it or one of it parents evaluates false.

Categories