views:

62

answers:

2

Hi!

For a while now, I've been working on a JAVA-based web project, and have found this website to be very helpful on numerous occasions.
So, 'got some problems of my own now - and would appreciate if you help out!

Ok, so Here's the thing -
I'm trying to render a list of messages, each of which consists of a message title and a message body. The trick I'm working on is that the message body, for as long as the title (which is an a4j:commandLink) hasn't been clicked-on, should be hidden. And once the title's clicked - the body should be displayed. And once its clicked again - hide. And so forth.
Here's what I did at the JSF side (some parts have been omitted for simplicity):

<a4j:repeat var="msg" value="#{ForumRenderJSF.messages}">
    <a4j:region id="msgAjaxRegion" renderRegionOnly="true">
    <a4j:outputPanel id="msgPanel" ajaxRendered="true">
    <rich:panel style="width: 100%; border: 0">
    <a4j:form id="msgForm">

        <!--
         The message's title.
         Each click results in either the revealing or hiding of the message's body.
         -->

        <a4j:commandLink value="#{msg.title}" action="#{ForumRenderAssistJSF.reevaluateRender}"/>
        <h:outputText value="  By: <i>#{msg.userNick}</i>,   #{msg.timestamp}" escape="false"/>

        <!--
         The message's body.
         -->

        <!-- A (textual) flag, indicating whether the body should be rendered. -->
        <h:inputText id="renderBodyFlag"/>

        <br/>
        <!-- The body. -->
        <a4j:outputPanel rendered="#{rich:findComponent('renderBodyFlag').value == true}">
            <h:outputText value="#{msg.body}"/>
        </a4j:outputPanel>

    </a4j:form>
    </rich:panel>
    </a4j:outputPanel> <!-- msgPanel -->
    </a4j:region>

</a4j:repeat>

Note the usage of:
1. A dummy "renderFlag" field (should be hidden, eventually), which value denotes whether the body should be rendered.
2. A backing bean for rendering assistance (ForumRenderAssistJSF); It goal is to flip the proper renderFlag's value from "true" to "false", and vice-versa.
3. An a4j:region to isolate each message when firing the request for ForumRenderAssistJSF.reevaluateRender() -- so that the bean can find the right "renderFlag" field.

As for the bean:

public class ForumRenderAssistJSF {
public void reevaluateRender()
    {
        FacesContext    context = FacesContext.getCurrentInstance();
        UIViewRoot      root = context.getViewRoot();
        UIComponent     renderFlagComp = (new UIComponentLookup()).lookup(root, compLookup); // My recursive search
        String          renderFlagVal = (String) ((HtmlInputText)renderFlagComp).getValue();

        if (!renderFlagVal.equals("true"))
        {
            ((HtmlInputText)renderFlagComp).setValue("true");
        }
        else
        {
            ((HtmlInputText)renderFlagComp).setValue("false");
        }
    }
}

AND THE PROBLEM IS:
The trick actually works -- but only for the first message in the list! For the rest of them, I see that the server can reach the right renderFlag input-text component (tested by inserting values at the client), but for some reason - the client always renders it blank (no content) upon AJAX reply!

I tried digging deep inside richfaces tutorials and manuals, and to me it seems like everything is as it should be. So, I'm kind'a lost here, and as I said - would deeply appreciate your help in regards!

Thanks!

A: 

Have you tried using a rich:simpleTogglePanel? It seems to provide all the functionality you need.

gedim
Sure does, but seems to require facelets. But thanks, you've been of great help.
und0
A: 

Interesting... I'll look into it! Thanks!

und0