我如何在单击另一个 <h:panelGrid> 时更新 <h:panelGrid>?
How can I update a <h:panelGrid> when am clicking in another <h:panelGrid>?
例如,我试图在 panelgrid
单击另一个面板网格时更新总价。
<c:forEach items="#{coinsBean.selectedCountryVo.selectedGameVo.operatorGamePackageVos}" var="operatorGamePackageVo" >
<h:panelGrid id="pack_#{operatorGamePackageVo.id}"
styleClass="bord"
style="border:solid #cbcbcb; margin: 4vmin; min-width: -webkit-fill-available;text-align: center;border-radius: 2vmin;"
onclick="selectUcs(this.id);"
>
<p:commandLink style="border-radius: 2vmin; padding: 2vw;background-size: 4vmin;text-align: center;font-family: 'Cairo', sans-serif "
update="totalSelected" action="#{coinsBean.selectOperatorGamePackageVo(operatorGamePackageVo)}"
value="#{operatorGamePackageVo.packageName}"
/>
</h:panelGrid>
</c:forEach>
<h:panelGrid columns="1" id="totalSelected" style="background-color: white;
padding-left: 5vh;border-radius: 0 0 1vh 1vh;margin-bottom: 2vh;width:95%;margin:auto;text-align: left ;">
<h:panelGrid>
<p id="total" style="color: #FE6D2C;font-size: 3.5vmin;font-family: 'Cairo', sans-serif;text-align: center;font-weight: bold;margin: auto;" dir="rtl">
price
</p>
<p id="total1" style="color: black;font-size: 3vw;font-family: 'Cairo', sans-serif;text-align: center;font-weight: bold;margin: auto" dir="rtl">
#{coinsBean.selectedCountryVo.selectedGameVo.selectedOperatorGamePackageVo.price}
</p>
</h:panelGrid>
</h:panelGrid>
一旦我点击上面那个!
解决方案
无法将 ajax 添加到 h:panelGrid
(请参阅 解释 了解原因)。
最好的方法可能是使用 h:commandScript
(自 JSF 2.3 起)。
只需将此添加到您页面的某处:
<h:form>
<h:commandScript name="someFunction" render="totalSelected" />
</h:form>
现在,当您想要更新 panelGrid 时,只需执行 someFunction()
。
在您的情况下,将此添加到应该更新另一个的 panelGrid:
<h:panelGrid ... onclick="someFunction();">
...
</h:panelGrid>
也可以使用 css(糟糕的 hack)来拉伸 h:commandLink
以适应整个 panelGrid(我可以根据要求添加)。
说明
基本上您可以使用的每个组件(h:panelGrid
、h:commandLink
等)都是 java class。但并不是每个人 can/should 都做同样的事情。如果您想将 ajax 行为与组件一起使用,则特定组件必须实现 ClientBehaviourHolder
接口。这是为 h:commandButton
、h:inputText
、h:commandScript
等操作组件保留的。 h:panelGrid
没有实现这个接口。
例如,我试图在 panelgrid
单击另一个面板网格时更新总价。
<c:forEach items="#{coinsBean.selectedCountryVo.selectedGameVo.operatorGamePackageVos}" var="operatorGamePackageVo" >
<h:panelGrid id="pack_#{operatorGamePackageVo.id}"
styleClass="bord"
style="border:solid #cbcbcb; margin: 4vmin; min-width: -webkit-fill-available;text-align: center;border-radius: 2vmin;"
onclick="selectUcs(this.id);"
>
<p:commandLink style="border-radius: 2vmin; padding: 2vw;background-size: 4vmin;text-align: center;font-family: 'Cairo', sans-serif "
update="totalSelected" action="#{coinsBean.selectOperatorGamePackageVo(operatorGamePackageVo)}"
value="#{operatorGamePackageVo.packageName}"
/>
</h:panelGrid>
</c:forEach>
<h:panelGrid columns="1" id="totalSelected" style="background-color: white;
padding-left: 5vh;border-radius: 0 0 1vh 1vh;margin-bottom: 2vh;width:95%;margin:auto;text-align: left ;">
<h:panelGrid>
<p id="total" style="color: #FE6D2C;font-size: 3.5vmin;font-family: 'Cairo', sans-serif;text-align: center;font-weight: bold;margin: auto;" dir="rtl">
price
</p>
<p id="total1" style="color: black;font-size: 3vw;font-family: 'Cairo', sans-serif;text-align: center;font-weight: bold;margin: auto" dir="rtl">
#{coinsBean.selectedCountryVo.selectedGameVo.selectedOperatorGamePackageVo.price}
</p>
</h:panelGrid>
</h:panelGrid>
一旦我点击上面那个!
解决方案
无法将 ajax 添加到 h:panelGrid
(请参阅 解释 了解原因)。
最好的方法可能是使用 h:commandScript
(自 JSF 2.3 起)。
只需将此添加到您页面的某处:
<h:form>
<h:commandScript name="someFunction" render="totalSelected" />
</h:form>
现在,当您想要更新 panelGrid 时,只需执行 someFunction()
。
在您的情况下,将此添加到应该更新另一个的 panelGrid:
<h:panelGrid ... onclick="someFunction();">
...
</h:panelGrid>
也可以使用 css(糟糕的 hack)来拉伸 h:commandLink
以适应整个 panelGrid(我可以根据要求添加)。
说明
基本上您可以使用的每个组件(h:panelGrid
、h:commandLink
等)都是 java class。但并不是每个人 can/should 都做同样的事情。如果您想将 ajax 行为与组件一起使用,则特定组件必须实现 ClientBehaviourHolder
接口。这是为 h:commandButton
、h:inputText
、h:commandScript
等操作组件保留的。 h:panelGrid
没有实现这个接口。