How do I disable keyboard entry in a primefaces extensions timePicker inside a primefaces datatable ? There is no property by default like p:calendar.
Can i do it via js ?
I have to either disable keyboard entry or manipulate the component such that it hides the popup and the user can only type in values. Tried the latter using css but it failed. Please help.
Thanks !
As far as I am aware you can't do it on the component itself...YET.
What has worked for me with JSF regarding a similar issue was the Javascript/Jquery approach. For instance you take an Id or a class of certain component you want to disable the keyboard on and do the following.
$(document).ready(function() {
$("#yourComponentId").keydown(false);
});
or this:
...
$(".yourComponentClassname").on("keydown keypress keyup", false);
...
As far as I am aware if you give the component an attribute like:
... readonly = true ...
your backing bean will ignore it unless you mess around with:
FacesContext#getRenderResponse();
Hope this helps a bit.
Related
I used an ice:dataTable component to display data, somehow there was a default onscroll event in the target div which doesn't make any sense to me and it had brought some positioning problems to other float elements within the page. I want to disable this action, but I didn't find any approach to control this.
It called the function below:
var input = document.getElementById('targetId'); clearTimeout(ice.pid);
ice.pid = setTimeout(function() {
input.value =
document.getElementById('targetId_scroll').scrollTop;
window.iceSubmitPartial(null, input, event);
}, 400);
I had a similar problem with ICEFaces and as we upgraded the JSF and ICEFaces versions the best solution was to change the tags:
ice:dataTable tag to ace:dataTable and the columns inside from ice:column to ace:column.
But, if you didn't upgrade ICEFaces version, I guess you could use a JavaScript or jQuery in some point of your code removing the onscroll attribute, like:
document._getElementsByXPath("//div[contains(#onscroll,'scroll')]")[0].removeAttribute("onscroll")
This one isn't a good one, just a example, cause you can remove scroll from other tables.
jQuery('.myClass div[id$="_scroll"]')[0].removeAttribute("onscroll")
On a page I have some fields that I want to be "readonly" (in my meaning they can't be accessed but they will store values, read earlier question in this matter if issues...).
I use a client JS setting these attributes on page load:
$(".readonly").attr('readonly', true);
If I have a partial update on any of these fields the attribute is lost and the field is accessible.
What is the best practice to overcome this and make it work?
Every partial refresh has a oncomplete method bound to it. What you could do is add code to the oncomplete method so the item is being set readonly again. Another, better, approach would be not to change the attribute clientside but to have hidden fields which are used to store the data.
When you have an event bound to for instance an Link control you can change the oncomplete code by clicking in your source pane on the event tag. When you browse the events section in the properties pane you will see the onComplete, onError, onStart properties. You can add your own clientside script in these properties.
Before trying to overcome the "problem" You shoud try to understand what exactly partial refresh do and where the state of application is kept.
Unfortunately partial refresh is replacing current html content (or rather part of it) with a newly created one and only form fields that has backing controls will keep state.
I suggest You should try setting readonly property on controls which You would like to make readonly (if there is some logic here You can always use ssjs).
Optionally You can try to preserve the state on the client side by using csjs global variables but this is rather hard to manage.
And one more thing - try to use the technology to solve the problem(xpages) and try not to hack Your way through with use of stuff that You accidentally know (jquery).
I would agree with jjtbsomhorst on using onComplete event. But another alternative could be setting the readonly property via code like this:
var textField:com.ibm.xsp.component.xp.XspInputText = getComponent("inputText1");
var readOnlyAttr:com.ibm.xsp.complex.Attr = new com.ibm.xsp.complex.Attr("readonly", "readonly");
var list:java.util.ArrayList = new java.util.ArrayList();
list.add(readOnlyAttr);
textField.setAttrs(list);
You could call this on the afterPageLoad event of the XPage. But I really don't know whether this would be the best way to about!
I changed my static menu file (header.xhtml) with a mega menu with a model.
Like this:
<p:megaMenu model="#{menuController.megaModel}" autoDisplay="false" styleClass="menu-bar" >
</p:megaMenu>
So far so good, its working great and building just like I expected.
The problem is, on my form pages, when validation fails for the secound time...
I get this error:
javax.faces.FacesException: Cannot remove the same component twice: j_idt15:j_id2 com.sun.faces.context.StateContext$AddRemoveListener.handleAddRemoveWithAutoPrune(StateContext.java:493)
com.sun.faces.context.StateContext$AddRemoveListener.handleRemove(StateContext.java:372)
Looking at the generated HTML I cant find this String "j_idt15:j_id2", but I can find:
<div id="j_idt14:j_idt15" class="ui-menu ui-menubar ui-megamenu ui-widget ui-widget-content ui-corner-all ui-helper-clearfix menu-bar" role="menubar">
and this:
So... I really don´t understand. My MenuController is a sessionBean:
#Component
#Scope("session")
public class MenuController implements Serializable {
#PostConstruct
public void init(){
todosModulos = moduloService.findAll();
modulosAcesso = extrairModulos();
createMegaMenu();
}
...So.. some notes:
I figured out that this error occurs on versions of Mojarra above 2.1.9.
(I am using 2.1.10). So one possible solution is changing the JSF imp to My Faces.
I Tried that, but it buged my structure (my composite components stoped working and dynaForm also).
I tried some workarounds but no sucess. This is what I tried:
Overriding AbstractMenu and Marlon Patrick's solution (PT-BR).
Simply doesn´t work =[
EDIT -> Creating the MenuItem
MenuItem anItem = new MenuItem();
anItem.setOutcome(item.getOutcome());
anItem.setValue(item.getRotulo());
anItem.setIcon(item.getIcone());
From what I saw you already tried my two workarounds: overwrite AbstractMenu and put PhaseListener.
Well, what I realize is that the component that was the problem I had MenuBar and what you are trying to use is the MegaMenu, perhaps the solutions that I do not work for MegaMenu, although I believe that should work yes.
What I would say to you is to check the following:
1 - When you override the class AbstractMenu you are sure the PrimeFaces started to use it? To make sure it puts a break point there and if he sees to the execution flow. If you do not stop, because PrimeFaces is still using its own class.
2 - When attempting to use the solution with PhaseListener, which I prefer and use today, you noted that you need to replace a piece of code with your own code? Basically you'll have to remove only the actions of menu items that are links, because they are causing this problem. The menu items are actions that should remain. In my case, I knew what actions were or links by ID, then you will have to differentiate somehow believe that by also id. Also, put a break point to make sure that your PhaseListener was duly registered and that is intercepting the flow of execution.
I have a form which one of it's fields is a code and description, also a button for opening a popup window that contains a list of all of the available codes.
when the user double clickes a row from that table i want to set these values to the code and description. - how can this be done?
Another question, I want to create this popup and table to be initialized dynamically - by that i mean that if i have a few forms in my application, when ever i have a field which has a description i want to be able to open this popup and to see the available list for that field. (every field can be from a diffrent table). is it possible to create something like that? if so, how?
Any help will be appritiated,
Thank's In Advance.
Yes, it is possible. Even more, many component libraries have ready to use popup/dialog components, such as RichFaces with <rich:popupPanel> and PrimeFaces with <p:dialog>.
If you do not want to use a component library for some reason, you would need to create a custom component for this which generates basically an absolutely positioned HTML <div> element with a CSS overlay which get shown/hidden by JS on a particular click/action. The HTML/CSS/JS part should be relatively simple if you are familiar with those languages. The JSF part is somewhat hard if you have never created a custom component before, but it should be possible with a composite component as well, so you could also just create one with pure XHTML. The updating/refreshing can just take place by the usual <f:ajax> means.
In my application i have three buttons, If i click on one button I have to disable all the button till the operation on that button is finished.
I dont know how to disable the other two buttons. Kindly help.
Use JavaScript to get the HTML element from the DOM and then set its disabled attribute.
document.getElementById('clientId').disabled = true;
Note that the 'clientId' is the autogenerated HTML element ID. Rightclick page and View Source to find it out. If this contains prefixes like j_id and so on, then you need to give all parent UINamingContainer components like <h:form>, <h:dataTable>, <f:subview> and so on a fixed component ID, so that the client ID doesn't need to be autogenerated anymore.