The second form uses less space in client-side state saving, and I
generally use it.
It's a bit more work when you have multiple bean properties to save,
though. Five properties would mean five tags, and you have to remember
to add a new tag every time you add a new persisting property.

The first form requires that your backing bean implement Serializable
(or StateHolder).   Most standard java objects (like boolean/Boolean)
already do this for you.

On 9/15/06, L Frohman <[EMAIL PROTECTED]> wrote:
Thanks, is there any benefit in

<t:saveState value="#{testBean}"/>
vs.
<t:saveState value="#{testBean.boolean}"/>

?

-----Original Message-----
From: Mike Kienenberger [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 14, 2006 8:44 PM
To: MyFaces Discussion
Subject: Re: data getting lost from form

Add a <t:saveState value="#{testBean}"/>

Your backing bean is request-scoped, so _boolean will be false by the time
you're restoring the view, applying the values, validating, etc.

- bean created
- view rendered
- bean out of scope

- form submitted

- bean recreated
- form processed
- view rendered
- bean out of scope

On 9/14/06, L Frohman <[EMAIL PROTECTED]> wrote:
>
>
> It seems like the jsp page below should work.
> If the checkbox is checked and then submit is pressed, the input text
> box appears.
> But then anything entered in the input text is lost - the setter is
> never called.
> Can anyone tell me why? Something to do with timing of the component
> binding?
>
> faces-config.xml
> <managed-bean>
>    <managed-bean-name>testBean</managed-bean-name>
>    <managed-bean-class>TestBean</managed-bean-class>
>    <managed-bean-scope>request</managed-bean-scope>
> </managed-bean>
>
>
>
> test.jsp
> <%@ page session="false"
> contentType="text/html;charset=utf-8"%>
> <%@ taglib uri="http://java.sun.com/jsf/html"; prefix="h"%> <%@ taglib
> uri="http://java.sun.com/jsf/core"; prefix="f"%> <f:view>
>         <html>
>                 <body>
>                         <h:form>
>                                 <h:selectBooleanCheckbox
> value="#{testBean.boolean}" />
>                                 <h:inputText value="#{testBean.string}"
> rendered="#{testBean.boolean}" />
>                                 <h:commandButton
action="#{testBean.action}"
> value="submit" />
>                         </h:form>
>                 </body>
>         </html>
> </f:view>
>
>
> TestBean.java
> public class TestBean {
>
>     private String _string;
>     private int _int;
>     private boolean _boolean;
>
>     public boolean isBoolean() {
>         return _boolean;
>     }
>     public void setBoolean(boolean _boolean) {
>         this._boolean = _boolean;
>     }
>     public int getInt() {
>         return _int;
>     }
>     public void setInt(int _int) {
>         this._int = _int;
>     }
>     public String getString() {
>         return _string;
>     }
>     public void setString(String _string) {
>         System.out.println("_string = " + _string);
>         this._string = _string;
>     }
>     public void action() {}
> }
>
>
>
>
>


Reply via email to