1

I am working on creating a dynamic table using JSTL forEach and a h:dataTable and have all of the controls and potential error message showing nicely, but am now stuck on getting the value set for each of the control. I will need to create (I think) a dynamic EL expression to set the value, but have not been able to get any of my versions to work. I was hoping to build out the expression using c:out, but found out that that tag is not available in JSF2.

So, is it possible to build a dynamic expression in the page? How can I set the expression in the backing bean if the control hasn't been built yet ?

 <h:dataTable id="dtDetails" styleClass="slate_table" value="#{remediationDetail.eventList}" var="dataItem">
 <c:forEach items="#{remediationDetail.eventHeaders}" var="key">
  <h:column>
      <f:facet name="header">#{key.fieldDefinition.fieldConfiguration.customLabel}</f:facet>
         <h:inputText value="" id="txtNumber" styleClass="remediation_textbox error_marker" title="#{remediationDetail.errorMessages(dataItem.id, key.fieldDefinition.id)}">
           <f:convertNumber maxFractionDigits="0" maxIntegerDigits="19"/>
  </h:column>
 </c:forEach>
</h:dataTable>

As always, any help or direction is appreciated.

Regards,

Mike

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
MikeR
  • 633
  • 8
  • 21
  • i think u ll have a problem when the foreach will create more then one inputText with the same id.U can avoid this to happen if u omit the the id attribute. – Bardelman Apr 02 '13 at 17:32
  • Have u tried to write something like : #{remediationDetail.errorMessages(#{dataItem.id},#{key.fieldDefinition.id} ? – Bardelman Apr 02 '13 at 17:37
  • I haven't gone down that path yet, but was going to shortly. The dynamic expression would be quicker wince I will know the exact variable/method to reference for the expression. Calling the backing bean will make me use reflection and run a loop through the objects variables. The Id should be unique after JSF takes over and the page is rendered. – MikeR Apr 02 '13 at 17:45
  • Okay, just tell us if it works, i m curious to know it :) – Bardelman Apr 02 '13 at 18:15
  • 1
    Since you're using JSF 2, it would be better to use `` and build your `` based on this. Also, you might want to read this Q/A: [JSTL in JSF2 Facelets… makes sense?](http://stackoverflow.com/q/3342984/1065197)
    – Luiggi Mendoza Apr 02 '13 at 21:18
  • @LuiggiMendoza Thanks for the suggestion, but that still would not get me to the spot where I need to be. Since the table is dynamic and I do not know the columns that are going to be displayed I would still need to build a dynamic expression to select the column value. I ended up choosing to go the JSTL route because of my desire to have access to the component tree after the page is built. – MikeR Apr 03 '13 at 14:55
  • You can achieve the same with ``. For these problems, you should not use `` at all, instead use `` to iterate through your rows columns and another `` to iterate through your columns. – Luiggi Mendoza Apr 03 '13 at 15:37

2 Answers2

0

I was not being able to create a Dynamic EL Expression. So, I ended using the index of the c:forEach to help define what values I am looking for. The only catch for this result is that I would be expecting the data that I am about to display to have the same number of positions in the array.

<c:forEach items="#{remediationDetail.eventHeaders}" var="key" varStatus="looper">
    <h:column>
        <f:facet name="header">#{key.fieldDefinition.fieldConfiguration.customLabel}</f:facet>
<h:inputText id="txtNumber" value="#{dataItem.entityList[looper.index].val}">
   <f:convertNumber maxFractionDigits="0" maxIntegerDigits="19"/>
</h:inputText>
    </h:column>
 </c:forEach>
MikeR
  • 633
  • 8
  • 21
0

In my case the following helped to build dynamic EL.

<ui:param name="beanName" value="myBackedBean"/>
<ui:param name="propertyName" value="field1"/>
<ui:param name="nestedPropertyName" value="field1"/>

<p:inputTextarea value="#{sessionScope[beanName][propertyName][nestedPropertyName]}"/>

Inspired of this topic

Community
  • 1
  • 1