Page 1 of 1

Primefaces Icarus inputtext setting focus from bean

Posted: 29 Jul 2017, 21:36
by redstone
Hi
I am developing Web POS (Point of sales) using Icarus Theme and a code bar reader "HoneyWell".
I am trying to set focus trough back bean to an inputnumber component once code bar is read. But never control get focus.

Elements used:
- Primefaces 6.1 Community
- Primefaces Icarus Theme.
- HoneyWell Voyager 9520 codebar scanner
-Tomcat 9 M21
- Browser: Chrome 59.0.3071.115 (Build oficial) (64 bits) / FireFox 54.0.1 (64-bits) / Microsoft Edge

Source code resume
1. xhtml

1.1 <h:form id="frmColMan" >
(note: I used <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> -as also other jquery versions- changing focus works!, but
some primefaces components like p:selectOneMenu, p:calendar got malfunctions or unexpected behavior)
1.2 <p:focus id="focusID" for="#{vwCodeBar.focusProperty}" /> (note: component recomended for setting focus)
1.3
<div class="ui-g-6 ui-lg-6">
<p:inputText id="itBarCode" value="#{vwCodeBar.strCodeBar}" placeholder="Bar code input" tabindex="2"
onkeydown="enterToTab(event);"
onkeypress="if (event.keyCode == 13) { onchange(); return false; }">
<p:ajax event="change"
listener="#{vwCodeBar.codeBarBreakDown}"
update="valuePay, focusID" />
</p:inputText>
</div>
(note: this code piece for reading bar code input)
1.4
<script>
trigger: function focusField(){
jQuery( document ).ready(function( $ ) {
$('#valuePay').focus('init');
});
$('#valuePay').focus();
document.getElementById("frmColMan:valuePay").focus();
this.focus();
return false;
}
(also used in different several times, but without results
function focusField(){
document.getElementById('frmColMan:valuePay').focus();
}

function focusField(){
$("#frmColMan\\:valuePay").focus();
}
)
function enterToTab(event){
if (event.which === 13) {
event.keyCode = 9;
$("#frmColMan\\:valuePay").get(0).focus();
$("#valorPagar").focus();
$('input[name="valuePay"]').focus();
return false;
}
}

</script>

2. Java Back bean
@ManagedBean(name="vwCodeBar")
@ViewScoped
public class CodeBar extends Exception {
public CodeBar() {
focusProperty = "itBarCode"; //set focus ok!
}
//Getting code bar configuration
public void codeBarBreakDown(AjaxBehaviorEvent event){
.
.
.
strValue = strCodeBar.substring(posIni , posFin);
valueToPay = transformToPay(strValue);
RequestContext.getCurrentInstance().update("frmColMan:valuePay"); //does not work or refresh component focus
focusProperty = "valuePay"; //does not work or refresh component focus
}
}


As you can see , Javascript and Primefaces is used in order to set focus from backing bean programmatically. But without any success.
Change focus is required for work flow process.

Thanks in advance

Re: Primefaces Icarus inputtext setting focus from bean

Posted: 02 Aug 2017, 07:05
by dsalazar
My advice, try to check in your xhtml if you get p:dialog components inside your <h:form> </h:form>. If so, move it all them out side h:form.
Then test again your focus setting.
So long.

Re: Primefaces Icarus inputtext setting focus from bean

Posted: 02 Aug 2017, 17:41
by redstone
dsalazar: bearing your advice, I moved dialogs and awesomely it works, except on Microsoft Edge. Any ideas why?

Re: Primefaces Icarus inputtext setting focus from bean

Posted: 04 Aug 2017, 13:10
by aragorn
This isn't an Icarus Layout or Theme issue. Please use core forum; viewforum.php?f=3