Primefaces Icarus inputtext setting focus from bean

Post Reply
redstone
Posts: 2
Joined: 21 Jun 2017, 22:54

29 Jul 2017, 21:36

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

dsalazar
Posts: 3
Joined: 01 Jul 2014, 07:00

02 Aug 2017, 07:05

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.

redstone
Posts: 2
Joined: 21 Jun 2017, 22:54

02 Aug 2017, 17:41

dsalazar: bearing your advice, I moved dialogs and awesomely it works, except on Microsoft Edge. Any ideas why?

User avatar
aragorn
Posts: 2697
Joined: 29 Jun 2013, 12:38

04 Aug 2017, 13:10

This isn't an Icarus Layout or Theme issue. Please use core forum; viewforum.php?f=3

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest