Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>&lt;ui:repeate&gt;</code>, a render time tag works correctly but not <code>&lt;c:foreEach&gt;</code>, a view build time component (I can't clarify why) but in this particular case, I found <code>&lt;p:dataGrid&gt;</code> is more suitable. The XHTML has been modified accordingly as follows.</p> <pre><code>&lt;p:panel id="dataPanel" rendered="#{zoneChargeManagedBean.renderedDataPanel}" closable="true" toggleOrientation="horizontal" toggleable="true" header="Data"&gt; &lt;p:dataGrid columns="3" value="#{zoneChargeManagedBean.list}" var="row" paginator="true" paginatorAlwaysVisible="false" pageLinks="10" rows="15"&gt; &lt;p:watermark for="txtCharge" value="Enter charge."/&gt; &lt;p:tooltip for="lblCharge" value="Some message."/&gt; &lt;p:column&gt; &lt;p:outputLabel id="lblCharge" for="txtCharge" value="#{row[1]}"/&gt;&lt;br/&gt; &lt;p:inputText id="txtCharge" value="#{row[2]}" onkeydown="return isNumberKey(event, this.value);" converter="#{bigDecimalConverter}" label="#{row[1]}" required="false" maxlength="45"&gt; &lt;f:validator validatorId="negativeNumberValidator"/&gt; &lt;f:attribute name="isZeroAllowed" value="false"/&gt; &lt;f:validator validatorId="bigDecimalRangeValidator"/&gt; &lt;f:attribute name="minPrecision" value="1"/&gt; &lt;f:attribute name="maxPrecision" value="33"/&gt; &lt;f:attribute name="scale" value="2"/&gt; &lt;/p:inputText&gt; &lt;h:message for="txtCharge" showSummary="false" style="color: #F00;"/&gt; &lt;/p:column&gt; &lt;/p:dataGrid&gt; &lt;p:commandButton id="btnSubmit" update="dataPanel messages" actionListener="#{zoneChargeManagedBean.insert}" icon="ui-icon-check" value="Save"/&gt; &lt;p:commandButton value="Reset" update="dataPanel" process="@this"&gt; &lt;p:resetInput target="dataPanel" /&gt; &lt;/p:commandButton&gt; &lt;/p:panel&gt; </code></pre> <hr> <p>The managed bean:</p> <pre><code>@Controller @Scope("view") public final class ZoneChargeManagedBean implements Serializable { @Autowired private final transient ZoneChargeService zoneChargeService=null; private ZoneTable selectedZone; //Getter and setter private List&lt;Object[]&gt;list; //Getter and setter private boolean renderedDataPanel; //Getter and setter public ZoneChargeManagedBean() {} public void ajaxListener() { if(this.selectedZone!=null){ list=zoneChargeService.getZoneChargeList(this.selectedZone.getZoneId()); renderedDataPanel=true; } else { renderedDataPanel=false; } } public void insert() { //Just do whatever is needed based on the list with new values which is retrieved when &lt;p:commandButton&gt; as shown in the given XHTML is clicked. if(selectedZone!=null&amp;&amp;zoneChargeService.addOrUpdate(list, selectedZone)) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Message Summary", "Message")); } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, "Message Summary", "Message")); } } } </code></pre> <p>The service method as in the <code>ajaxListener()</code> method returns a list of type of an array of objects - <code>List&lt;Object[]&gt;</code>.</p> <pre><code>public List&lt;Object[]&gt;getZoneChargeList(Long id) { return entityManager.createQuery("select w.weightId, w.weight, zc.charge from Weight w left join w.zoneChargeSet zc with zc.zoneTable.zoneId=:id order by w.weight").setParameter("id", id).getResultList(); } </code></pre> <p><sub>I can't use the corresponding JPA criteria query which is intended because the <code>with</code> operator which doesn't seem to be supported by the JPA criteria API.</sub></p> <p>This method is invoked when an item from <code>&lt;p:selectOneMenu&gt;</code> is selected which is not covered in this question.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload