I'm facing an issue while scanning a barcode with an usb barcode scanner.
The scanner's functioning is simple: you scan a barcode and it write the read string as a text(tested on a .txt file) but when I use on the follow code it returns me to the home page logging out from the website.
<h:outputText value="barcode*" />
<p:inputText value="#{myBean.barcode}"
maxlength="16>
<p:ajax event="blur"
update="#this"
listener="#{myBean.checkBarcode()}"/>
</p:inputText>
I tried some debug and saw that the method checkBarcode is not called, so i suppose that the scanner do something authomatic, like printing a tab or new line or something else.
is there some attribute on the p:ajax or the inputText that can avoid this kind of issue?
Related
I have following code to work with a selectOneMenu provided by BootsFaces. It works totally fine, except that the error message (validation failed) is not shown up. With a <h:selectOneMenu>, it also works. Also with a <b:inputText, perfectly. The error message is simple not displayed with <b:selectOneMenu>.
<b:messages id="nachrichten" showDetail="true" showSummary="false" />
<b:selectOneMenu value="#{userprofile.user.year}" required="true" requiredMessage="Pls enter year">
<f:selectItem itemLabel="year auswählen" itemValue="#{null}" />
<f:selectItems value="#{yearHelper.allYears}" var="year" itemValue="#{year}" itemLabel="#{year.name}" />
<f:facet name="append">
<h:outputText value="" />
</f:facet>
</b:selectOneMenu>
How can I fix, that the message is shown up while using <b:selectOneMenu>?
It's kind of a bug. Actually, you're using a feature we never promised. Funny thing is, I did implement some extra logic on when the required attribute is set to true. That's weird because I prefer the JSF303 bean validation style (and that, in turn, is the reason why I forgot to implement required).
I've opened a bug for you: https://github.com/TheCoder4eu/BootsFaces-OSP/issues/136.
Update 07/29/2015: As of BootsFaces 0.7.0++ (probably 0.8.0), the bug has been fixed.
I have a rich:calendar on a jsf page like this:
<rich:calendar id="someDate"
name="aName" validatorMessage="wrong format!"
enableManualInput="true" datePattern="dd/MM/yyyy"
value="#{MyBean.someDate}" >
</rich:calendar>
<rich:message id="validationSomeDate" for="someDate"
tooltip="false" showDetail="false">
<f:facet name="errorMarker">
<h:graphicImage id="imgError" value"/someImage.gif" />
</f:facet>
</rich:message>
<rich:tooltip for="validationSomeDate" value="wrong format!"/>
This succesfully validates that the user didn't write some nonsense into the date field like "12456" or something. The problem is, this validation is only triggered when the form is submitted. I would like to have this checked as soon as the date field loses focus, all client-side. Is there a way to do this?
I tried using a
<rich:validator>
tag but I'm using richfaces 3.x and this tag isn't available.
<rich:ajaxValidator event="onblur">
doesn't help either...
I'm learning some of JSF and I want know somethings. I already searched a lot in Google, Stack Overflow and famous websites like Mkyong and I didn't find the solution.
Actually I have one input text and a DataTable in the same page. The code appears something like this:
<h:form>
<h:inputText id="discipline"
value="#{disciplineMBean.name}"
valueChangeListener="#{disciplineMBean.updateList}">
<f:ajax event="keyup" reRender="myTable"/>
</h:inputText>
<h:commandButton value="Add" action="#{disciplineMBean.create}">
</h:commandButton>
</h:form>
<h:form>
<h:dataTable id="myTable" var="disciplina"
value="#{disciplinaMBean.disciplineList}">
<h:column>
<f:facet name="header">Name</f:facet>
<h:outputText value="#{discipline.name}" />
</h:column>
</h:dataTable>
</h:form>
What I want is: when the inputText value change, I want call the method "updateList", that will update the disciplineList with the matching disciplines (the connection with DB is ok). After that I want reRender "myTable" with the matched results - via Ajax, without page reload.
public void updateList(){
if( getName() != null && getName().length() > 0){
this.setDisciplineList( <working_connection_with_db_sending_getName()> );
}else{
this.setDisciplineList( <working_connection_with_db_all_results> );
}
}
Summarizing, I want that when user type something in input field, the disciplines list got updated with the matched disciplines - everything without page reload, when user change input field, the table is updated in real-time with the matching disciplines.
I can do something like that?
<h:inputText id="discipline" value="#{disciplineMBean.name}">
<f:ajax event="keyup" action="#{disciplineMBean.updateList}" reRender="myTable" />
</h:inputText>
Edit:
I already solved my problem, but I don't know if my way is the best way to do this things. So I will leave this question open and wait a answer explainning a better way to do this (for future users that need a similar feature). When a good answer be posted, I will give this the best answer.
Note: I translated the variable names, so sorry if I forget something.
I need to trigger an ajax update upon change to a text box, which is a <p:autoComplete> component. I have observed that if the user opts to type the text manually, the event is a change, whereas if the user clicks one of the suggestions for the autocomplete, the event is itemSelect. So I added two <p:ajax> children to the input, each calling the same method and having the same update list, but one having event="change" and the other event="itemSelect".
However, I now discover something odd. For example, while in normal server mode I opened my page and typed "12". The autocomplete offered "1233" and "1234" as suggestions. I clicked "1233" and seemingly nothing happened. I clicked again and everything else filled in.
Repeat this in the debugger with a breakpoint on the event handler, and I can see that after the first click, the value is "12" and on the second click, it becomes "1233".
By switching commenting out the two different <p:ajax> I can see the different consequences. Without the "change" one, the handler is never called if the user selects an autocomplete suggestion, and without the "itemSelect" one, the handler is never called if the user types manually. But with both of them, there are two calls, and I'm sure there will be complaints about the double-click.
Some pseudo-code for those that like, first the xhtml:
<p:autoComplete id="itemId" value="#{myBacker.myBean.itemNumber}"
required="true" completeMethod="#{myBacker.idAutoComplete}">
<p:ajax event="itemSelect" update="beanDetails"
listener="#{myBacker.idChangeEventListener()}" />
<p:ajax event="change" update="beanDetails"
listener="#{myBacker.idChangeEventListener()}" />
</p:autoComplete>
<h:panelGroup id="beanDetails">
<h:panelGroup rendered="#{not empty myBacker.myBean.institutionName}">
<h:outputText value="#{myBacker.myBean.institutionName}" />
<!-- Continues with address, phone, etc.. -->
</h:panelGroup>
</h:panelGroup>
Then the Java backing bean code:
public void idChangeEventListener() {
myBean = myDAO.getDetails(myBean);
// another couple of init-type method calls
}
Give the parent tag a widgetVar attribute, then add this little attribute to the <p:ajax event="change" ...> child tag:
onstart="if(widgetVarName.panel.is(':visible')) return false;"
When the question was written, we were on PrimeFaces version 3.5, if I recall correctly. Since then, we need to update the solution to:
onstart="if(PF('widgetVarName').panel.is(':visible')) return false;"
with thanks to mwalter for pointing out the change.
I have a problem similar to the one found here : JSF selectItem label formatting.
What I want to do is to accept a double as a value for my and display it with two decimals. Can this be done in an easy way?
I've tried using but that seems to be applied on the value from the inputText that is sent to the server and not on the initial value in the input field.
My code so far:
<h:inputText id="december" value="#{budgetMB.december}" onchange="setDirty()" styleClass="StandardBlack">
<f:convertNumber maxFractionDigits="2" groupingUsed="false" />
</h:inputText>
EDIT: The above code actually works. I was fooled by JDeveloper that didn't update the jsp page even when I did a explicit rebuild of my project and restarted the embedded OC4J server. However, after a reboot of my computer everything was fine.
If I'm not misunderstanding your requirement, I was able to achieve formatting of the value in the input box during the rendering of the view with:
<h:inputText id="text1" value="#{...}">
<f:convertNumber pattern="#,###,##0.00"/>
</h:inputText>
I was using the Standard Faces Components in my vendor-branded Eclipse so I'm assuming the pattern attribute is part of standard JSF.
If what you are trying to do is make the value of the input text field change on screen (to correct user input), you should probably look into using one of the JSF ajax frameworks like Rich Faces.
A possible example would look like this:
<h:inputText id="december" value="#{budgetMB.december}" styleClass="StandardBlack">
<f:convertNumber maxFractionDigits="2" groupingUsed="false" />
<a4j:support event="onblur" reRender="december" />
</h:inputText>
I haven't tested this, but I think it may work.
It seems you're actually formatting a currency. There already exists a specific formatter to handle currencies that you can assign many options to:
<f:convertNumber type="currency" />
Some interesting attributes of this tag are: locale, currencyCode, integerOnly, currencySymbol and pattern.