You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Stefan Neumann <st...@freiheit.com> on 2006/07/19 20:12:39 UTC

Conditional working for dynamic components

Hi all,

I have a profile structure editor, where I can choose different Values
and add them to a list. Each property of such a profile can have
different datatypes like String, Address(contains street, city, zip
code), CreditCard (owner, number ...)  and so on.

After this profile structure is saved I want to display the profile in
the normal known way with

<label>: <InputFields>

Inputfields would be in case of a String simply an inputText, in case of
an address several new label with their inputFields.

street: <inputText>
zip code: <inputText>
city: <inutText>

So  tried something like that


<ui:repeat value="#{controller.profileStructure}" var="prop">
  <c:choose>
    <c:when test="prop.isString">
      DISPLAY STRING STUFF
    </c:when>
    <c:when test="prop.isAddress">
      DISPLAY ADDRESS STUFF
    </c:when>
    <c:otherwise>
      UNKNOWN TYPE!
    </c:otherwise>
</ui:repeat>

After a long time of trying I just realised, that this will never work,
because the test of the jstl stuff is calculated ONCE before rendered.
But in this case, prop is null and so it cannot be used. (I chosed this
was first, because you have an otherwise and can see, if a type
implementation is missing.

But next try, using the jsf rendered attribute:

<tr jsfc="ui:repeat" value="#{controller.profileStructure}" var="prop">

  <h:panelGroup rendered="#{prop.isString}">
    <!-- display label -->
    <td>
      <span jsfc="h:outputLabel" value="#{prop.name}" />
    </td>
    <td>
      <span jsfc="h:inputText" value="#{prop.value}" />
    </td>	
  </h:panelGroup>

  <h:panelGroup rendered="#{prop.isAddress}">
    <!-- display label -->
    <td>
      <span jsfc="h:outputLabel" value="#{prop.name}" />
    </td>
    <td>
      <!-- Display Address as a block -->
      <table>
        <tr>
          <td>
            Street:
          </td>
          <td>
            <span jsfc="h:inputText"
value="#{prop.value.street}" /> 			  </td>	
        </tr>
	[.. Display other fields of address ..]
      </table>
    </td>
  </h:panelGroup>
</tr>

BUT,.... (argh!!)

I had already read in this list, but have not remembered, also the parts
are not rendered the are also interpreted, so also I want to display a
String value, the template tries to <string-value>.street and that
throws an exception.


Back to my question: How can I do just a functionality? I cannot have a
conditional statement and I am not able to not render stuff. What else
can I do?


Thanks in advance for your help,

Stefan

Re: Conditional working for dynamic components

Posted by Martin Grotzke <ma...@javakaffee.de>.
Hello Stefan,

i do not have the right and complete answer, but one or two hints:
- have a look at the facelets FAQ
  (http://wiki.java.net/bin/view/Projects/FaceletsFAQ), there's
  an entry about build-time and render-time tags, and the difference
  on c:forEach and ui:repeat
- on this list there was a thread about the evaluation of child
  components depending on the parent's rendered attribute:
  http://www.mail-archive.com/users_at_myfaces.apache.org/msg24702.html
  (replace the _at_)

Perhaps this might take you some steps further,
cheers,
Martin :)


On Wed, 2006-07-19 at 20:12 +0200, Stefan Neumann wrote:
> Hi all,
> 
> I have a profile structure editor, where I can choose different Values
> and add them to a list. Each property of such a profile can have
> different datatypes like String, Address(contains street, city, zip
> code), CreditCard (owner, number ...)  and so on.
> 
> After this profile structure is saved I want to display the profile in
> the normal known way with
> 
> <label>: <InputFields>
> 
> Inputfields would be in case of a String simply an inputText, in case of
> an address several new label with their inputFields.
> 
> street: <inputText>
> zip code: <inputText>
> city: <inutText>
> 
> So  tried something like that
> 
> 
> <ui:repeat value="#{controller.profileStructure}" var="prop">
>   <c:choose>
>     <c:when test="prop.isString">
>       DISPLAY STRING STUFF
>     </c:when>
>     <c:when test="prop.isAddress">
>       DISPLAY ADDRESS STUFF
>     </c:when>
>     <c:otherwise>
>       UNKNOWN TYPE!
>     </c:otherwise>
> </ui:repeat>
> 
> After a long time of trying I just realised, that this will never work,
> because the test of the jstl stuff is calculated ONCE before rendered.
> But in this case, prop is null and so it cannot be used. (I chosed this
> was first, because you have an otherwise and can see, if a type
> implementation is missing.
> 
> But next try, using the jsf rendered attribute:
> 
> <tr jsfc="ui:repeat" value="#{controller.profileStructure}" var="prop">
> 
>   <h:panelGroup rendered="#{prop.isString}">
>     <!-- display label -->
>     <td>
>       <span jsfc="h:outputLabel" value="#{prop.name}" />
>     </td>
>     <td>
>       <span jsfc="h:inputText" value="#{prop.value}" />
>     </td>	
>   </h:panelGroup>
> 
>   <h:panelGroup rendered="#{prop.isAddress}">
>     <!-- display label -->
>     <td>
>       <span jsfc="h:outputLabel" value="#{prop.name}" />
>     </td>
>     <td>
>       <!-- Display Address as a block -->
>       <table>
>         <tr>
>           <td>
>             Street:
>           </td>
>           <td>
>             <span jsfc="h:inputText"
> value="#{prop.value.street}" /> 			  </td>	
>         </tr>
> 	[.. Display other fields of address ..]
>       </table>
>     </td>
>   </h:panelGroup>
> </tr>
> 
> BUT,.... (argh!!)
> 
> I had already read in this list, but have not remembered, also the parts
> are not rendered the are also interpreted, so also I want to display a
> String value, the template tries to <string-value>.street and that
> throws an exception.
> 
> 
> Back to my question: How can I do just a functionality? I cannot have a
> conditional statement and I am not able to not render stuff. What else
> can I do?
> 
> 
> Thanks in advance for your help,
> 
> Stefan
-- 
Martin Grotzke
Bernstorffstr. 17, 22767 Hamburg
Tel.      +49 (0) 40.98239888
Mobil     +49 (0) 170.9365656
E-Mail    martin.grotzke@javakaffee.de
Online    http://www.javakaffee.de

Re: Conditional working for dynamic components

Posted by Mike Kienenberger <mk...@gmail.com>.
On 7/19/06, Stefan Neumann <st...@freiheit.com> wrote:
> But next try, using the jsf rendered attribute:
>
> <tr jsfc="ui:repeat" value="#{controller.profileStructure}" var="prop">
>
>   <h:panelGroup rendered="#{prop.isString}">
>     <!-- display label -->
>     <td>
>       <span jsfc="h:outputLabel" value="#{prop.name}" />
>     </td>
>     <td>
>       <span jsfc="h:inputText" value="#{prop.value}" />
>     </td>
>   </h:panelGroup>
>
>   <h:panelGroup rendered="#{prop.isAddress}">
>     <!-- display label -->
>     <td>
>       <span jsfc="h:outputLabel" value="#{prop.name}" />
>     </td>
>     <td>
>       <!-- Display Address as a block -->
>       <table>
>         <tr>
>           <td>
>             Street:
>           </td>
>           <td>
>             <span jsfc="h:inputText"
> value="#{prop.value.street}" />                           </td>
>         </tr>
>         [.. Display other fields of address ..]
>       </table>
>     </td>
>   </h:panelGroup>
> </tr>
>
> BUT,.... (argh!!)
>
> I had already read in this list, but have not remembered, also the parts
> are not rendered the are also interpreted, so also I want to display a
> String value, the template tries to <string-value>.street and that
> throws an exception.
>
>
> Back to my question: How can I do just a functionality? I cannot have a
> conditional statement and I am not able to not render stuff. What else
> can I do?

Doing it with a UIData iterator (like ui:repeat) and rendered should
be the correct way to go.   I'm surprised that it is throwing an
exception.   Are you sure it's doing what you think it's doing?
These El expressions look wrong:  rendered="#{prop.isAddress}.   This
would mean that your java code has a method named getIsAddress or
isIsAddress.   Is that the case?

It'd probably be most helpful to post an example Exception.