有没有办法告诉JSF它<table>
在使用时不应该呈现元素<h:selectOneRadio>
?我不使用表格,在这种情况下它完全没有意义.
任何帮助表示赞赏!
每次用户点击单选按钮时,我都会尝试显示验证消息.
这仅在我单击提交按钮时有效,但在单击单选按钮时不起作用:
<h:form id="form">
<p:panel id="panel">
<ui:repeat value="#{questionsBean}" var="question">
<h:panelGrid columns="3" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="#{question.questionText}" />
<p:selectOneRadio id="question" value="#{question.response}"
validator="#{question.validate}" required="true">
<f:selectItem itemLabel="Yes" itemValue="Yes" />
<f:selectItem itemLabel="No" itemValue="No" />
<p:ajax update="msgQuestion" event="change"/>
</p:selectOneRadio>
<p:message for="question" id="msgQuestion" />
</h:panelGrid>
</ui:repeat>
<p:commandButton id="btn" value="Save" update="panel" partialSubmit="true"/>
</p:panel>
</h:form>
Run Code Online (Sandbox Code Playgroud) 如何使用p:selectOneRadio
javascript/jquery 获取选择的收音机?
由于p:selectOneRadio
不使用单选标签,我不知道如何使用 CSS 选择器获取选中的选项。
<p:selectOneRadio onchange="reactToChangedRadio()" >
<f:selectItem itemLabel="....." itemValue="..." />
<f:selectItem itemLabel="....." itemValue="..." />
<f:selectItem itemLabel="....." itemValue="..." />
</p:selectOneRadio>
Run Code Online (Sandbox Code Playgroud) 我正在使用p:selectOneRadio
with p:ajax
和另一个component(p:inputText
)的值,而不是在我的bean中绑定它的值.
如果我使用p:selectBooleanCheckbox
的行为正是我需要的,那么在调用ajax中的方法之前更新bean.这是一个错误p:selectOneRadio
或者这是它的默认行为吗?
我正在使用JSF2,PrimeFaces 4
在XHTML代码:
<p:selectOneRadio id="enumId" value="#{xyzController.entity.enumValor}"
disabled="#{disabled}" required="true" plain="true">
<f:selectItems value="#{xyzController.enum}" var="item"
itemLabel="#{messages[ELUtils.evaluateExpression(itemLabelEL)]}"
itemValue="#{item}" />
<p:ajax event="change" listener="#{xyzController.aoTrocar}"
update="panelDominioFields" process="@form" />
</p:selectOneRadio>
<p:outputPanel layout="inline" id="panelDominioFields">
<p:inputText id="valorId"
value="#{xyzController.entity.valorNumericoValido}"
rendered="#{xyzController.mostrarCampoDominioNumerico}"
required="true">
<f:convertNumber type="number" locale="#{localeController.locale}"
currencyCode="#{localeController.currencyCode}" />
</p:inputText>
</p:outputPanel>
Run Code Online (Sandbox Code Playgroud) 我有表格中显示的页面列表.每个页面都有属性homePage,我想在数据表中有一列单选按钮要在此属性上绑定,用户只能检查一个值.如何在服务器端获得此值?
我看到了一些例子如下:http: //jforum.icesoft.org/JForum/posts/list/14157.page,但我想知道在这种情况下最佳做法是什么.
在JSF 2.0中我有以下内容
<h:selectOneRadio value="#{StageGate.sketchesSG002006Decision}" onclick="validateMyRadioButton()" id="radio26">
<f:selectItem itemValue="Accepted" itemLabel="Accepted" id="accepted"/>
<f:selectItem itemValue="Rejected" itemLabel="Rejected" id="rejected"/>
</h:selectOneRadio>
Run Code Online (Sandbox Code Playgroud)
我输出为
O Accepted O Rejected
^^
Run Code Online (Sandbox Code Playgroud)
我想要的是在两个单选按钮之间添加空格,以便输出
O Accepted O Rejected
^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
我尝试
在两个单选按钮之间添加,但它无法正常工作.我在下一行收到单选按钮.
<h:selectOneRadio value="#{StageGate.sketchesSG002006Decision}" onclick="validateMyRadioButton()" id="radio26">
<f:selectItem itemValue="Accepted" itemLabel="Accepted" id="accepted"/>
<f:selectItem itemValue="Rejected" itemLabel="Rejected" id="rejected"/>
</h:selectOneRadio>
Run Code Online (Sandbox Code Playgroud)
知道如何做到这一点?
没有生成的HTML
是
<table id="radio26">
<tr>
<td>
<input type="radio" checked="checked" name="radio26" id="radio26:0" value="Accepted" onclick="validateMyRadioButton()" /><label for="radio26:0"> Accepted</label></td>
<td>
<input type="radio" name="radio26" id="radio26:1" value="Rejected" onclick="validateMyRadioButton()" /><label for="radio26:1"> Rejected</label></td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
当我 
在<table id="radio26">
语句之前添加一个空格时.
我有一个selectOneRadio
标签,所有单选按钮选项都显示在一行上.如何为每行/每行创建一个选项?
在我的JSF视图中,我使用的是p:selectOneRadio.现在我必须在客户端更改此组件的值作为副作用.在这个组件的Client Side API中,我发现以下内容,如果我找到了正确的方法,我认为我可以使用它:
PrimeFaces.widget.SelectOneRadio=PrimeFaces.widget.BaseWidget.extend(
{
// ...
select:function(a){
this.checkedRadio=a;
a.addClass("ui-state-active")
.children(".ui-radiobutton-icon")
.addClass("ui-icon-bullet").removeClass("ui-icon-blank");
a.prev().children(":radio").prop("checked",true)}
});
Run Code Online (Sandbox Code Playgroud)
对我来说(没有太多关于JS的知识)看起来我必须传递类似于我想要选择的单选按钮的实例.我已经通过多种方式尝试过这种方法,但它们都不起作用:
<p:selectOneRadio widgetVar="sel" id="id-sel" >
<f:selectItem itemValue="#{false}" itemLabel="n/a" />
<f:selectItem itemValue="#{true}" itemLabel="date" />
</p:selectOneRadio>
<p:commandButton onclick="PF('sel').select(sel.inputs[1]);"/>
<p:commandButton onclick="PF('sel').select(PF('sel').inputs[1]);"/>
<p:commandButton onclick="PF('sel').select( $('input:radio[id*=id-sel\\:1]') );"/>
<p:commandButton
onclick="PF('sel').select(document.getElementById('menuform:id-sel:1'));"/>
Run Code Online (Sandbox Code Playgroud)
但是,我也尝试直接传递值和/或标签(这适用于selectOneMenu).再次没有成功(但在这种情况下并不奇怪)
<p:commandButton onclick="PF('sel').select('date');"/>
<p:commandButton onclick="PF('sel').select('true');"/>
<p:commandButton onclick="PF('sel').select(1);"/>
<p:commandButton onclick="PF('sel').select(true);"/>
<p:commandButton onclick="PF('sel').select(#{true});"/>
Run Code Online (Sandbox Code Playgroud)
谁知道该怎么办?
深入研究RadioRenderer
源代码我注意到了以下几点:
方法
@Override
protected void renderOption(FacesContext context,
UIComponent component,
Converter converter,
SelectItem curItem,
Object currentSelections,
Object[] submittedValues,
boolean alignVertical,
int itemNumber,
OptionComponentInfo optionInfo) throws IOException
Run Code Online (Sandbox Code Playgroud)
RadioRenderer
正在从标准public void encodeEnd(FacesContext context, UIComponent component)
Renderer方法调用类中的 override .但是有以下代码:
Iterator<SelectItem> items =
RenderKitUtils.getSelectItems(context, component);
//some code
while (items.hasNext()) {
SelectItem curItem = items.next();
idx++;
// If we come across a group of options, render them as a nested
// table.
if (curItem instanceof SelectItemGroup) {
// do some
else {
// …
Run Code Online (Sandbox Code Playgroud) 我有一个h:selectOneRadio
组件,我已映射到Boolean
支持bean中的(不是布尔值).加载时,单选按钮没有默认选择选项,单选按钮不是必填字段.
示例代码:
JSF页面摘录:
<h:form>
<h:selectOneRadio value="#{pagecode.test}">
<f:selectItem itemValue="#{true}" itemLabel="Yes"/>
<f:selectItem itemValue="#{false}" itemLabel="No"/>
</h:selectOneRadio>
<h:commandButton value="Save" action="#{pagecode.save}"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)
支持Java页面代码:
package pagecode;
public class JSFBooleanTestView extends PageCodeBase {
protected Boolean test;
public Boolean getTest() {
return test;
}
public void setTest(Boolean test) {
this.test = test;
}
public String save() {
return "JSFBooleanTestView";
}
}
Run Code Online (Sandbox Code Playgroud)
faces-config.xml摘录:
<managed-bean>
<managed-bean-name>pagecode</managed-bean-name>
<managed-bean-class>pagecode.JSFBooleanTestView</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
Run Code Online (Sandbox Code Playgroud)
由于test
没有默认值,单选按钮开始未选中.由于不需要该字段,我的期望是在没有选中单选按钮的情况下按下"保存"按钮会导致测试为空.相反,测试被指定为false.
我尝试过的不同选项没有效果:
设置 h:selectOneRadio required="false"
添加到web.xml:
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)添加到web.xml:
<context-param>
<param-name>org.apache.el.parser.COERCE_TO_ZERO</param-name>
<param-value>false</param-value>
</context-param> …
Run Code Online (Sandbox Code Playgroud)我有seleconeradio,例如:
<h:selectOneRadio value="#{myBean.selectedValue}" layout="pageDirection">
<f:selectItems value="#{myBean.myList}" var="a" itemValue="#{a}" itemLabel="#{a}"/>
</h:selectOneRadio>
Run Code Online (Sandbox Code Playgroud)
其中myList是整数列表,例如1,3,2,4.如果用户在myBean selectedValue中选择第二个元素(即3),那么我想得到selectItems项的索引.
我应该在f:selectItems itemValue标签中写什么?或者这是不可能的?
PS我可以通过创建一个新类来实现它,在该类中我有索引属性并创建该类的新列表,给出正确的索引.但这是非常糟糕的解决方案.
selectoneradio ×11
jsf ×9
jsf-2 ×7
primefaces ×4
ajax ×1
boolean ×1
client-side ×1
datatable ×1
html-table ×1
javascript ×1
jquery ×1
line-breaks ×1
null ×1
renderer ×1
whitespace ×1