What's the difference between p:resetInput vs p:ajax resetValues=true? - ajax

I have seen a lot of answers talking about the use of <p:resetInput> and <p:ajax resetValues="true"> works in the same way.
In this case Why does my form isn't reseting his styling after render? just the <p:ajax> component worked for me.
I have read this posts but they always are treated as the same:
How can I apply p:resetInput or p:ajax resetValue =“true” for
p:dataList?
How can I populate a text field using PrimeFaces AJAX after
validation errors occur?
I still can't understand the difference between this two if anyone have some documentation about it I would be really grateful.

p:resetInput was basically introduced in PrimeFaces-Extensions long time before resetValues on f:ajax/p:ajax existed.
Also resetValues is only available for JSF 2.2+ users, while p:resetInput even works on JSF 2.0.

Related

JSF PrimeFaces ajax update excluding one component

I got a form, that includes outputPanel that I need to update, excluding one of its component (it containts calendar, that resets after I call update, I want to prevent that)
<p:ajax update=":form1:outputPanel1 :not(form1:outputPanel1:nestedOutputPanel)"/>
But I have no idea how can I achieve something like this (above example is not working)?
The PrimeFaces update attribute takes one or more expressions separated by a space (or comma). Normally (in plain JSF) those expressions are client IDs, but in PrimeFaces you can also use selectors. A selector is executed and results in a list of client IDs to update. You could use a selector to select all the components that need to be updated and exclude the component you don't want to update.
You could add a style class to the component you want to exclude and use something like:
update="#(.parent :not(.exclude))"
As you can read in the top answer on the linked question, the #(...) selector will be used as a jQuery selector. So you can easily test selectors in your browser's JavaScript console as $("...").
See also:
How do PrimeFaces Selectors as in update="#(.myClass)" work?

Which is better between using IDs or styleClass while using Primefaces Ajax update to render UI components? [duplicate]

This question already has an answer here:
How do PrimeFaces Selectors as in update="#(.myClass)" work?
(1 answer)
Closed 5 years ago.
I can use IDs of components or a styleClass used in all of the components.
<p:ajax event="change" process="#none" listener="#{someListener()}"
update="#(.someStyleClass)"/>
<p:ajax event="change" process="#none" listener="#{someListener()}"
update="someId1 someId2 someId3"/>
Which approach is better and why?
EDIT: I know that CSS selector uses IDs in the background. I am not asking how it works. I am asking which is a better approach ( for maybe different cases ) and why.
You seem to be confused with the concept of these CSS selectors with the updating of PrimeFaces components.
Simple, if you have requirement to update just one component use ID selector. While, if you have numerous (more than one) components to be updated on certain action, use CLASS selector.
Update:
Although you can set comma separated IDs of components in your update attribute, but the difference of using CLASS selector would be that those components are interrelated (similar) by any mean or you don't want to use separate ID attribute on each component.

Disable other inputtext on change of one inputtext

I'm using JSF2.1 with PrimeFaces 4.0 and surprisingly I'm unable to find a simple solution, how to disable a field if another field is already filled instead. E.g. if I enter a number in the "plus quantity" field and I leave the field by clicking or using tab, the "minus quantity" field should be disabled.
All I found is to do something like this
<p:inputText id="minusQty" disabled="#{not empty order.plusQty}"/>
<p:inputText id="plusQty" value="#{order.plusQty}">
<f:ajax update="minusQty" />
</p:inputText>
but I find it a bit heavy to call the server for such a simple task. I also don't want to add custom JS code. I guess there's a built-in way in JSF/PF but I cannot find it...
but I find it a bit heavy to call the server for such a simple task
Measure it instead of making assumptions.
I also don't want to add custom JS code
It boils down to just using the right tool for the job. The code which you've so far looks okay, apart from the <p:ajax> and <f:ajax> mixup (the <f:ajax> doesn't support update attribute). I'd only use <p:ajax partialSubmit="true"> to reduce request payload, especially if this is part of a relatively large form.
Might you eventually go in the JS direction, keep in mind that enabling/disabling a HTML DOM element in client side doesn't enable/disable the JSF component in server side. In other words, when you do so with pure JS, then hackers will still be able to submit the value anyway. Always keep this in mind when considering either client or server side for some tasks.

How can I find what triggered a dirtyforms popup?

I have a form that normally works with respect to dirtyforms. However, there is one circumstance where a jquery-ui datapicker calendar will pop up the "are your sure" dialog when a date is clicked.
I emphasize that this normally works correctly. The situation is related to the initial conditions of the form data source. Things work when the object being referenced is existing, but not if it is new. So I am sure somewhere there is a difference in the initial conditions of the form. But in theory the form should be identical.
How can I find what is causing the popup so I can fix my issue?
Well, I did find what was causing my problem by comparing the HTML of the working and non-working situations. (Not an easy task since there were many non-relevant differences.)
Seems that the original coder did a strange thing. Left out some Javascript function declarations when the page was "new" but of course did not eliminate the calls on those functions.
So I guess that the javascript errors were the root cause. At least when I include those function declarations everything works correctly.
By default, most anchor links on the page will trigger the dialog. We don't have a hard-coded selector of all potential 3rd party widgets, you must manually take inventory of whether these widgets use hyperlinks and ignore them if they are causing errant behavior.
See ignoring things for more information.
I was unable to reproduce this behavior using Dirty Forms 2.0.0, jQuery UI 1.11.3, and jQuery 1.11.3. However, in previous versions of Dirty Forms, you can probably use the following code to ignore the hyperlink clicks from the DatePicker.
$('.ui-datepicker a').addClass($.DirtyForms.ignoreClass);

JSP form nested checkboxes

A project was passed onto me a short while ago which uses JSP for the view and spring 3.1 for the controller - both of which I have little experience in and as per usual, there are about 4 comments in the whole thing. Anyway, my issue is this, in replacing a
<form:checkboxes path="class.list" items="${items}" delimiter="<br />" />
With
<c:forEach var="item" varStatus="vs" items="${items}">
<form:checkbox path="class.list" item="${item}" />
// check if nesting is required, if so create div and nested list point to class.list.children
</c:forEach>
Seems to create additional elements in my class.list which are not selected leading to a break further on.
Any guidance would be greatly appreciated.
I would suggest leaving the form:checkboxes intact as it is a compact way to generate checkboxes. I do not know of a compelling reason not to use the spring form tags if it is already in place and working. As to why you are seeing hidden fields. See here:
http://static.springsource.org/spring/docs/2.5.x/reference/view.html
Here is the relevant portion:
What you might not expect to see is the additional hidden field after each checkbox. When a checkbox in an HTML page is not checked, its value will not be sent to the server as part of the HTTP request parameters once the form is submitted, so we need a workaround for this quirk in HTML in order for Spring form data binding to work. The checkbox tag follows the existing Spring convention of including a hidden parameter prefixed by an underscore ("_") for each checkbox. By doing this, you are effectively telling Spring that “ the checkbox was visible in the form and I want my object to which the form data will be bound to reflect the state of the checkbox no matter what ”.
Hope this helps.

Resources