kukeltje wrote:Well, the position it is in now does not seem logical at all. Have you also tried putting it beween form and panelgrid?
Thank you for your time & response. You are right, that position does not seem logical. That is part of what drove me to post. It was only working if the focus was in the h:panelGrid, but if the p:focus is placed directly into the h:panelGrid the columns would be off whenever a h:facesMessage was displayed. The only other place that I could find to accomplish Goal #1 was inside the f:facet --yuck!!!
Yes, I had tried the position you are suggesting and it did not work. What is working for me now is as follows:
This code is on a form that displays a p:dialog (in another form) containing the p:focus in question...
Code: Select all
<p:menuitem value="New"
icon="ui-icon ui-icon-plus"
actionListener="#{serviceTypeController.prepareCreateServiceType}"
onclick="serviceTypeCreateDialogWVar.show();"
oncomplete="resetServiceTypeCreate();"
process="@this"
update="serviceTypeCreatePanel"
immediate="true"/>
Notice the oncomplete in the p:menuitem above. It calls javascript that sets the focus on the text field inside the dialog. I have tried adding the id of p:focus to the update list of the p:menuitem - no luck. Why won't p:focus do this on its own like in the showcase?
Code: Select all
function resetServiceTypeCreate() {
serviceTypeNameCreateWVar.value='';
document.getElementById('serviceTypeNameCreate').focus();
}
Okay the code below works beautifully. Once the javascript gives the p:inputText its focus, the user can tab and reverse tab between the p:inputText and the two p:commandButtons and nothing weird happens. If there is a validation error, the first field in error gets focus (i did throw several other p:inputText on the screen to test this). Once a successful process/update happens on the panel however, the p:inputText does not receive focus as it should. See the javascript below.
Code: Select all
<h:form id="serviceTypeCreateForm" prependId="false">
<p:dialog widgetVar="serviceTypeCreateDialogWVar"
header="Create New Service Type"
modal="true"
closable="false"
resizable="false"
showEffect="fold"
hideEffect="explode">
<p:panel id="serviceTypeCreatePanel">
<p:focus id="serviceTypeCreateFocus"/>
<h:panelGrid columns="3">
<h:outputText value="#{bundle.CreateServiceTypeLabel_servicetypename}"/>
<p:inputText id="serviceTypeNameCreate"
widgetVar="serviceTypeNameCreateWVar"
tabindex="1"
value="#{serviceTypeController.serviceType.servicetypename}"
required="true"
requiredMessage="#{bundle.CreateServiceTypeRequiredMessage_servicetypename}"/>
<p:message for="serviceTypeNameCreate"/>
</h:panelGrid>
<p:separator/>
<p:commandButton tabindex="2"
image="ui-icon ui-icon-check"
title="#{bundle.CreateServiceTypeSaveLink}"
actionListener="#{serviceTypeController.createServiceType}"
process="@this serviceTypeCreatePanel"
update="serviceTypeCreatePanel serviceTypeCreateFocus"
oncomplete="setNoErrorsFocus(args, 'serviceTypeNameCreate');"/>
<p:commandButton tabindex="3"
image="ui-icon ui-icon-close"
title="Close"
update="serviceTypeCreatePanel serviceTypes"
oncomplete="serviceTypeCreateDialogWVar.hide(); refreshDataTable(serviceTypesWVar); "
immediate="true"/>
</p:panel>
</p:dialog>
</h:form>
Once the first p:commandButton above is processed successfully, this will reset the focus to the first p:inputText.
Code: Select all
function setNoErrorsFocus(args, focusElementId) {
if(args.notValid || args.validationFailed)
return;
document.getElementById(focusElementId).focus();
}
Note - once I got it working to this point, I switched on "Good Vibrations" and danced like Marky Mark for an hour give or take.
Now, a couple of things. In the showcase, there is no id required for the p:focus. The p:commandButton updates the outer p:panel and that is enough to reset the focus to the first open text field (or first in error). Also, as mentioned before, I have to use javascript to initially set the focus and reset the focus to the appropriate p:inputText after a successful ajax process/update. For whatever reason, I can strip everything out to the bare bones like I did in my original post and it will not work as advertised in the showcase.
kukeltje wrote:Oh and complaining like you do often has the opposit effect.... (just a suggestion)
Umm... I would venture to say that 99.9% of all posts on this forum is someone complaining that something is not working for them. If you perceived something I wrote as problematic, feel free to point it out. Otherwise, I feel that I have made factual statements from my point of view. Anyone is free to try to convince me otherwise. I did say...
Cool Mr Ice wrote:
... No doubt I'm doing something idiodic for this to not work...
That implies I am willing to take 100% of the responsibility for <p:focus> not working for me.
Other than that, I'm just here to learn as much as I can about PrimeFaces and help wherever I can be of service. My heart goes out to anyone who is hurt by anything I have said. My mind does not.