dev@jsftemplating.java.net

Re: JSFTemplating: rendering component based on changing session attributes

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Mon, 11 Sep 2006 21:07:36 -0700

Hi Priti,

Nothing appears to be wrong. I tested this (see attached file which you
may run), and it works. The only difference is that I didn't have your
"changeRenderProp" handler, so I simply used setSessionAttribute() to
toggle it. In fact I added to buttons and was able to toggle back and
forth successfully. I did this to a staticText also...

I suspect your handler is not doing what you think it is doing.

As for my opinions on this approach...

* sun:alert automatically does this feature of you have or don't have a
"summary" property. So in instead of toggling "rendered", you toggle
"summary" from having a value to (null)... you'll get the same effect.
I imagine you have to do this anyway?

* I generally discourage the use of sessionScope in general. There are
good cases for using it, but if you can do w/o out it... I recommend
it. I have created the "pageSession" concept which may work well in
this case (value is stored w/ the page instead of in session).
requestScope will also often work in many cases (these values obviously
don't stick around for multiple requests, though).

Good luck!

Kne

Priti Tiwary wrote:
> Hi,
>
> i have a qs related to rendering (lets say alert) component based on
> attributes whose values are modified by other components(lets say button).
>
> i have initially set render to false..so alert is not rendered when the
> page is displayed first time..
>
> <!beforeCreate
> setSessionAttribute(key="render", value="$boolean{false}")
> />
>
> <sun:alert id="alert1" summary="Failed" details="check logs"
> rendered="#{sessionScope.render}"/>
> .....
> <sun:button id="Btn1" text="Next">
> <!command
>
> changeRenderProp(renderAlert=>$session{render})/>
> </sun:button>
>
>
> If changeRenderProp changes render value to true, after Next button
> click, the same page should be displayed (navigate is doing that) but
> with alert rendered..(not doing that right now)
>
> what is wrong here..?
> Priti
>
>


<sun:page>
    <sun:html>
        <sun:head id="head" />
        <sun:body>
            <sun:form id="form">
                <sun:staticText value="StaticText Visible!" rendered="#{sessionScope.render}" />
                <sun:alert id="alert1" summary="Failed" details="check" rendered="#{sessionScope.render}" />
                <sun:button text="Show">
                    <!command
                        setSessionAttribute(
                            key="render" value="$boolean{true}");
                    />
                </sun:button>
                <sun:button text="Hide">
                    <!command
                        setSessionAttribute(
                            key="render" value="$boolean{false}");
                    />
                </sun:button>
            </sun:form>
         </sun:body>
     </sun:html>
 </sun:page>