The example I have is the following:

On the left side of the page, we have a tree widget.  Browsing
to different nodes fills in entry widgets on the right side
of the page (properties for the nodes are on the right side.)

If you edit a value for one of the properties, then save it,
then browse to different tree nodes, the submitted value will
still be in those entry widgets.  Clearly, you want to see
the properties for the node you've selected, not ones for
something you've entered and saved.

-- Jon



On Apr 27, 2005, at 12:07 PM, Aaron Bartell wrote:

I was actually thinking the opposite. As long as I can remember back I have never used a form reset button (not even when I was doing my web programming with RPG CGI or PHP). I guess I would look at the scenario for why the user would ever want to clear a form. Is it because they want to cancel the current process they are going through, then give them a cancel button. Is it because they want to start completely over on the page? - I have never needed to do this in my life as a web page consumer. I might change a couple values in some fields but I never use the form reset button the web pages always provide. Just seems so meaningless (and dangerous because of data loss by accident), but maybe that is just me.

Aaron Bartell
http://mowyourlawn.com

-----Original Message-----
From: Jon Travis [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 27, 2005 12:58 PM
To: MyFaces Discussion
Subject: Re: resetting a form

Isn't he talking about things which have inputs?  Clearing
the ID is just resetting a read-only parameter, which is
a little different than UIInput components.

What I've been using is a method which recurses through a tree,
checking if components are UIInputs.  If they are, it
just does component.setValue(null), and
component.setSubmittedValue(null).

It seems like this would be a _very_ common thing for people
to want to do, but I'm surprised I haven't found it or
something similar in any documentation I have (including
Kito's book)

-- Jon


On Apr 27, 2005, at 2:48 AM, CsÃk Norbert wrote:

Check out my clear button. In faces-config I have a navigation rule
for the "clear" outcome: from page.jspx to page.jspx. It works for me.


public class PageBean { private String id; private String name;

        public PageBean() {
        }
        
        public String save() {
                FacesContext.getCurrentInstance().addMessage(null, new
FacesMessage("Saved."));
                
                id = "15";
                
                return "success";
        }
        
        public String delete() {
                FacesContext.getCurrentInstance().addMessage(null, new
FacesMessage("Deleted."));
                
                return clear();
        }
        
        public String clear() {
                id = "";
        
                return "clear";
        }
        
        public String editDetail() {
                FacesContext.getCurrentInstance().addMessage(null, new
FacesMessage("Detail."));
                
                return "success";
        }
        
        public boolean isLoaded() {
                return getId() != null && !getId().equals("");
        }

public String getId() {
return (id == null)
?
(String)FacesContext.getCurrentInstance().getExternalContext().getRequ e
stParameterMap().get("form:id")
: id
;
}


        public void setId(String id) {
                this.id = id;
        }

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }
}

And the JSF page:

<?xml version='1.0' encoding='ISO-8859-2'?>
<jsp:root xmlns="http://www.w3.org/1999/xhtml";
          xmlns:jsp="http://java.sun.com/JSP/Page"; version="2.0"
          xmlns:f="http://java.sun.com/jsf/core";
          xmlns:h="http://java.sun.com/jsf/html";>
  <f:view>
    <html>
      <jsp:output omit-xml-declaration="false"
doctype-root-element="html"

doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
<jsp:directive.page contentType="text/html;charset=ISO-8859-2"/>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-2"/>
<title>
Page
</title>
</head>
<body>
<h:form id="form">
<h:panelGrid columns="1">
<h:messages layout="table"/>
<h:panelGroup>
<h:commandButton value="New" action="#{PageBean.clear}"
immediate="true"/>
<h:commandButton value="Save" action="#{PageBean.save}"/>
<h:commandButton value="Delete"
action="#{PageBean.delete}"
immediate="true"
rendered="#{PageBean.loaded}"/>
</h:panelGroup>

<h:inputHidden id="id" value="#{PageBean.id}"/>

<h:panelGrid columns="2">
<h:outputLabel style="color:red" value="NÃv"/>
<h:inputText value="#{PageBean.name}" required="true"/>
<h:outputLabel value="ID"/>
<h:outputText value="#{PageBean.id}"/>
<h:outputLabel value="TÃpus"/>
<h:commandButton action="#{PageBean.editDetail}" value="Szerkeszt"
disabled="#{!PageBean.loaded}"/>
</h:panelGrid>

</h:panelGrid>
</h:form>
</body>
</html>
</f:view>
</jsp:root>




On 4/26/05, Vincent SEVEL <[EMAIL PROTECTED]> wrote:



Hi, I am trying to figure out the best/simplest way to reset a form
whose
fields are associated with a backing bean. I have found one incomplete
solution and would like to hear from other people.




I have got a person.jsp, which contains:

à      Input text bound to #{person.lastname}, required=true

à      Input text bound to #{person.firstname}

à      Button bound to #{personPage.console} that displays the
content of
the form in the console

à      Button bound to #{personPage.reset} that blanks out all the
fields
from the form



1) Initially I just removed the "person" object from the request map
and
returned null from the reset action. This caused the form to be
reset, but
also an validation error message to be displayed on the next page
about the
first field not being filled (ie: it is required).



2) Then, I set immediate='true' on the reset button, and rendered the
response directly from the reset action (ie:
FacesContext.getCurrentInstance().renderResponse()). Although this
skipped
the validation phase, it did not repopulate the components from the
value
binding expressions (ie: it does not blank out the form).



3) The only and last solution I can see at this time would be to
findComponent() the lastname & firstname fields, blank them out
manually and
renderResponse() immediately. But this extremely tedious and error
prone.



In short, I would like to deactivate validation and conversion for
some
special actions, but still feed from the backing bean during the
render
phase. Any ideas?



Thanks, source follows.

Vincent



person.jsp

<f:view>

            <h:messages styleClass="error" layout="table"
showDetail="true"
showSummary="false" tooltip="true"/>

            <h:form>

                        Lastname: <h:inputText id="lastname"
value="#{person.lastname}" required="true"/><p/>

                        Firstname: <h:inputText id="firstname"
value="#{person.firstname}"/><p/>

                        <h:commandButton value="Console"
action="#{personPage.console}"/>

                        <h:commandButton value="Reset"
immediate="true"
action="#{personPage.reset}"/>

            </h:form>

</f:view>



public class Person {

  private String lastname;

  private String firstname;

â



public class PersonPage {



  private Map getRequestMap() {

return
FacesContext.getCurrentInstance().getExternalContext().getRequestMap( )
;


  }



  public String console() {

    Person person = (Person) getRequestMap().get("person");

    System.out.println(person.getLastname()+"
"+person.getFirstname());

    return null;

  }





  public String reset() {

    getRequestMap().remove("person");

    FacesContext.getCurrentInstance().renderResponse(); // will skip
the
validation and conversion phases, but will not refresh from the
backing bean

    return null;

  }

}


--
 CsÃk Norbert          http://norbert.web.elte.hu/
 ProgramtervezÅ matematikus
 Trilobita Informatikai Rt. - rendszertervezÅ fejlesztÅmÃrnÃk
___ keep sm:)ing _________________________ooo__C( O O )L__ooo__
http://www.aion.hu/ - A csik.NET otthona
http://www.spreadfirefox.com/ - Rediscover the web
LÃgy pontos: MÃrj mikro-millimÃterben! JelÃlj krÃtÃval! VÃgj baltÃval!








Reply via email to