pe:resetInput don't work with tree

Community Driven Extensions Project
Post Reply
rbr
Posts: 3
Joined: 03 Sep 2012, 16:10

03 Sep 2012, 16:17

I'm using primefaces 3.0 and I need to reset inputs validation on a tree select. I started implementing the pe:restInput as described on PrimeFaces Extentions site.
It works fine with buttons but when I'm using it with p:ajax into a tree it doen't work.

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

03 Sep 2012, 23:31

This should work. I remember I tested this. Can you post your code snippet please?
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

rbr
Posts: 3
Joined: 03 Sep 2012, 16:10

04 Sep 2012, 09:39

Here is my code.

Code: Select all

 <p:tree id="tree"  style="width: 190px;border: 0;padding-left: 0px;padding-right: 0px;" value="#{treeMB.root}"  var="node"  
                            selectionMode="single" selection="#{treeMB.selectedNode}"  >                                  

                        <p:ajax  event="select" process="@this" 
                                update="upd,dialog,contextMenu,confirmationDeleteTree" listener="#{treeMB.onNodeSelect}">
                            <pe:resetInput  event="select" for="upd"/>
                         
                        </p:ajax>
                        
                        <p:treeNode type="parent"  > 
                            <h:outputText style="font-weight: bolder;color: #{(node.deactivated) ? 'red' : null};" value="#{node.label}"/>  
                        </p:treeNode>  
                       
                    </p:tree> 

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

04 Sep 2012, 09:52

rbr wrote:Here is my code.

Code: Select all

 <p:ajax  event="select" process="@this"  update="upd,dialog,contextMenu,confirmationDeleteTree" listener="#{treeMB.onNodeSelect}">
       <pe:resetInput  event="select" for="upd"/>
</p:ajax> 

That doesn't work.

use it like this:

Code: Select all

<p:ajax  event="select" process="@this"  update="upd,dialog,contextMenu,confirmationDeleteTree" listener="#{treeMB.onNodeSelect}" />
<pe:resetInput  event="select" for="upd"/>
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

04 Sep 2012, 09:55

Right now, I'm writing my proposal for the JSF Expert Group regarding a built-in solution for reset input :)

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

04 Sep 2012, 10:25

cool! would you like to post it after the proposal is finished? :)
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

04 Sep 2012, 10:48

Hello Experts,

This is the first draft of the proposal to provide an easy way for resetting editable value holders
that save their value at viewstate after validation failures. Proposal is created by me and Kito Mann.

Issue number in spec issue tracker is 1060;

http://java.net/jira/browse/JAVASERVERF ... UBLIC-1060

Version 20120903

SECTION: Introduction

ACTION: read this for background on what this is all about.

EditableValueHolders mainly that derive from UIInput save the local value at view state
at process validations phase later to be used in model update phase where the local value is cleared.
When validation fails, component has no chance to clear the local value and page author cannot reset
the values of the component by updating the model values since the component uses the value at viewstate
first before deciding whether or not to resolve the model values. Sample scenario is as follows;

<h:form>
<h:messages />

<h:inputText id="firstname" value="#{bean.firstname}" required="true"/>
<h:inputText id="surname" value="#{bean.surname}" required="true"/>

<h:commandButton value="Ajax Save">
<f:ajax render="@form" execute="@form"/>
</h:commandButton>
<h:commandButton value="Non-Ajax Save" />

<h:commandButton value="Ajax Reset" actionListener="#{bean.reset}">
<f:ajax render="@form" execute="@this"/>
</h:commandButton>
<h:commandButton value="Non-Ajax Reset" actionListener="#{bean.reset}" immediate="true"/>

</h:form>

@ManagedBean
public class Bean {
private String firstname, surname;

//getter-setter

public void reset() {
firstname = null;
surname = null;
}
}

Steps to reproduce;

- Click the ajax save or non-ajax save without filling input fields to get a validation error
- Click reset or non-ajax buttons, although reset method is executed on bean, input components
still show old value as they retrieve it from the state.

SECTION: Known Solutions

ACTION: Please add if you are aware of any other solution

PrimeFaces

Provides a resetInput tag and a programmatic way, uses a tree visitor.

http://www.primefaces.org/showcase-labs ... tInput.jsf

PrimeFaces Extensions

A resetInput tag and uses a preRenderView event to reset.

http://fractalsoft.net/primeext-showcas ... tInput.jsf

MyFaces Trinidad

An action listener.

http://myfaces.apache.org/trinidad/trin ... tener.html

Omnifaces

An action listener for ajax cases.

http://showcase-omnifaces.rhcloud.com/s ... ener.xhtml


SECTION: Proposed Solution

ACTION: Please read this section and comment for feedback.

resetInput attribute in f:ajax

This part fixes the case for ajax requests, most of the time, page author
would like to reset what is being updated just like in Ajax Reset button in the sample code.
If f:ajax resets the components to update by going through PartialViewContext.getRenderIds()
component values will be reset and model values will be used to display. Sample;

<h:commandButton value="Ajax Reset">
<f:ajax render="@form" execute="@this" resetInput="true|false"/>
</h:commandButton>

For backward compatibility, default value of the resetInput attribute should be false. I know we don't want to add a context-param
but consider javax.faces.RESET_INPUT (false by default) to globally override the resetInput attribute setting. Still page authors
should override the global setting per component.

ResetInput Tag

This tag goes in core namespace named <f:resetInput /> to cover non-ajax requests. This is the solution
used in PrimeFaces and MyFaces Trinidad.

<h:commandButton value="Non-Ajax Reset" immediate="true">
<f:resetInput for="firstname surname or an ancestor of these components" />
</h:commandButton>

Programmatic API

Programmatic API is provided for flexibility in case page authors would like to decide when to reset. There are
two places where we can add this;

FacesContext.reset(String clientId)
FacesContext.reset(String clientIds as varargs)
UIViewRoot.reset(String clientId)
UIViewRoot.reset(String clientIds as varargs)

The implementation uses a TreeVisitor with a ResetInputVisitCallback.

rbr
Posts: 3
Joined: 03 Sep 2012, 16:10

04 Sep 2012, 10:53

Tanks for the replay. I tried it before doing my code as I posted it but it didn't work. I tried many several options like adding parent, changing the event (select, click, nodeSelect) even catching all events but it didn't work.

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

04 Sep 2012, 10:56

Sounds good :) Hopefully it will be accepted. Thanks for your work cagatay!
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests