嗨,大家好我想知道是否有我的问题的解决方案防止代码repeatation在JSF
基本上我用了10页重复的代码段,和而不只是复制并粘贴本人代码想知道我是否可以将其存储在模板文件中,并在每次需要使用它来防止代码在所有页面上重复时调用它。唯一的事情是我需要改变<p:tooltip
部分价值在每一页上
这是我期待添加到主文件和使用不断应用
<p:column>
<br></br>
<p:selectOneRadio id="radioButtons" value="#{formBean.number}" layout="grid" columns="1" required = "True"
requiredMessage="#{bundle.messageSelectMarkRange}" >
<f:selectItem itemLabel="0 - 19" itemValue="1" />
<f:selectItem itemLabel="20 - 39" itemValue="2" />
<f:selectItem itemLabel="40 - 49 " itemValue="4" />
<f:selectItem itemLabel="50 - 59" itemValue="5" />
<f:selectItem itemLabel="60 - 69" itemValue="6" />
<f:selectItem itemLabel="70 - 79" itemValue="7" />
<f:selectItem itemLabel="80 - 100" itemValue="8" />
<p:ajax process="@this" update="mySpinnerPanel" />
</p:selectOneRadio>
</p:column>
<p:column>
<p>
<p:button id="help0-19" icon="ui-icon-help">
</p:button>
<p:tooltip for="help0-19" value="No statement or very generalised with vague aims or objectives"
showEffect="clip" hideEffect="explode" />
</p>
<p>
<p:button id="help20-39" icon="ui-icon-help">
</p:button>
<p:tooltip for="help20-39" value="No statement or very generalised with vague aims or objectives"
showEffect="clip" hideEffect="explode" />
</p>
<p>
<p:button id="help40-49" icon="ui-icon-help">
</p:button>
<p:tooltip for="help40-49" value="Problem topic and aims and objectives apparent Shows limited understanding and analysis"
showEffect="clip" hideEffect="explode" />
</p>
<p>
<p:button id="help50-59" icon="ui-icon-help">
</p:button>
<p:tooltip for="help50-59" value="Problem topic and aims and objectives well presented, showing understanding and analysis. Key aspects of the context are covered"
showEffect="clip" hideEffect="explode" />
</p>
<p>
<p:button id="help60-69" icon="ui-icon-help">
</p:button>
<p:tooltip for="help60-69" value="Problem topic and aims and objectives well framed and viewed in wider context"
showEffect="clip" hideEffect="explode" />
</p>
<p>
<p:button id="help70-79" icon="ui-icon-help">
</p:button>
<p:tooltip for="help70-79" value="Problem is clearly shown to be challenging or shows originality and confidence in criticising assumptions"
showEffect="clip" hideEffect="explode" />
</p>
<p>
<p:button id="help80-100" icon="ui-icon-help">
</p:button>
<p:tooltip for="help80-100" value="Analysis of problem adds new insights"
showEffect="clip" hideEffect="explode" />
</p>
</p:column>
<p:column>
<p:outputPanel id = "mySpinnerPanel" layout ="pageDirection">
<!-- look into validation for this to prevent any unwanted values, better than the min max etc -->
<p>
<p:spinner id="ajaxspinner0-19" value="#{markingBean.markToEdit.markSectionOne}"
stepFactor = "1" min="0" max="19"
disabled = "#{formBean.number != 1}" >
<p:ajax update="ajaxspinnervalue " process="@this" />
</p:spinner>
</p>
<p>
<p:spinner id="ajaxspinner20-39" value="#{markingBean.markToEdit.markSectionOne}"
stepFactor = "1" min="20" max="39" disabled = "#{formBean.number != 2}">
<p:ajax update="ajaxspinnervalue" process="@this" />
</p:spinner>
</p>
<p>
<p:spinner id="ajaxspinner40-49" value="#{markingBean.markToEdit.markSectionOne}"
stepFactor = "1" min="40" max="49" disabled = "#{formBean.number != 4}">
<p:ajax update="ajaxspinnervalue" process="@this" />
</p:spinner>
</p>
<p>
<p:spinner id="ajaxspinner50-59" value="#{markingBean.markToEdit.markSectionOne}"
stepFactor = "1" min="50" max="59" disabled = "#{formBean.number != 5}">
<p:ajax update="ajaxspinnervalue" process="@this" />
</p:spinner>
</p>
<p>
<p:spinner id="ajaxspinner60-69" value="#{markingBean.markToEdit.markSectionOne}"
stepFactor = "1" min="60" max="69" disabled = "#{formBean.number != 6}">
<p:ajax update="ajaxspinnervalue" process="@this" />
</p:spinner>
</p>
<p>
<p:spinner id="ajaxspinner70-79" value="#{markingBean.markToEdit.markSectionOne}"
stepFactor = "1" min="70" max="79" disabled = "#{formBean.number != 7}">
<p:ajax update="ajaxspinnervalue" process="@this" />
</p:spinner>
</p>
<p>
<!--
This acts as markingBean.getMarkSectionOne.getSpinnerField() when rendering
and as markingBean.getMarkSectionOne.setSpinnerField(spinner.getValue()) when sending the request to the server
-->
<p:spinner id="ajaxspinner80-100" value="#{markingBean.markToEdit.markSectionOne}"
stepFactor="1" min="80" max="100" disabled="#{formBean.number != 8}">
<p:ajax update="ajaxspinnervalue" process="@this" />
</p:spinner>
</p>
</p:outputPanel>
</p:column>
<f:facet name="footer">
Total mark for this section is:
<h:outputText id="ajaxspinnervalue" value="#{markingBean.markToEdit.markSectionOne}" />
</f:facet>
</p:panelGrid>
</p>
<!-- testing to make sure the correct value is passed -->
<p>
<p:commandButton value="#{bundle.buttonNextSection}" icon ="ui-icon-disk" update="displayMark :growl" oncomplete="PF('dlg').show()" />
</p>
<p:dialog header="Confirm Mark" widgetVar="dlg" showEffect="fold" hideEffect="fold">
<h:panelGrid id="displayMark" columns="2" cellpadding="5">
<h:outputText value="Mark to be submitted: " />
<h:outputText value="#{markingBean.markToEdit.markSectionOne}" />
<p:commandButton id="save"
value="#{bundle.buttonSave}"
actionListener ="#{markingBean.editMark}"
update=":growl"
icon="ui-icon-disk"/>
</h:panelGrid>
</p:dialog>
和代码的唯一部分的代码,将需要改变的是每个p:button
是p:tootip
值
这是可能的吗?因为我认为它会精简应用程序很多,特别是新页面的生成
你想每页仅包含一次该代码?否则,你将不得不处理组件ID到.. – yannicuLar
是的代码只显示每页一次,但显示10页 – user2061913