我正在为一个在线教程中找到的hailstone序列编写一个代码,但是这样做我遇到了一个无法访问的语句错误.我不知道我的代码是否正确,如果我错了,我不想要纠正它的建议(关于冰雹序列,我想自己做... :)).我只想帮助解决第19行的"无法访问的语句"错误.
class HailstoneSequence {
public static void main(String[] args) {
int[][] a = new int[10][];
a[0][0] = 125;
int number = 125;
for (int i = 0;; i++) {
for (int j = 1; j < 10; j++) {
if (number % 2 == 0) {
a[i][j] = number / 2;
number = number / 2;
} else {
a[i][j] = (number * 3) + 1;
number = (number * 3) + 1;
}
}
}
for (int i …Run Code Online (Sandbox Code Playgroud) 如何使用单个比较器对对象中的所有字段进行排序?
例如:如果我有一个Employee带有三个字段,如对象Name,Eid和Salary.相反,即写3和比较Namecomparator,Eidcomparator并Salarycomparator进行排序,我只需要唯一一个可以进行排序基础上,我提交提供动态比较.
我是PrimeFaces的初学者,我不会保存包含输入密码的表单,但是当我尝试保存长度为2或3个字符的密码时,没有任何反应.按钮可能不起作用.这是我的榜样
<h:form id="mainForm">
<p:messages autoUpdate="true"/>
<p:panel header="Paramétrage des adresses">
<h:panelGrid id="createGrid"
columns="2"
cellspacing="100"
cellpadding="25">
<h:outputLabel for="pwd1" value="Mot de passe : *"/>
<p:password id="pwd1" value="#{adress.currentAdress.motDePasse}"
match="pwd2"
label="Mot de passe"
required="true"
maxlength="100">
<p:message for="pwd1"/>
</p:password>
<h:outputLabel for="pwd2" value="Confirmation Mot de passe : *"/>
<p:password id="pwd2"
value="#{adress.currentAdress.motDePasse}"
label="confirmation" required="true"/>
</h:panelGrid>
<p:commandButton id="saveAdress"
type="button" value="valider"
action="#{adress.save}"
update="createGrid dataTable"/>
</p:panel>
</h:form>
Run Code Online (Sandbox Code Playgroud) 当我输入有效值(仅数字)到inputText并单击commandButton然后我被重定向到response.xhtml.
当我输入无效值时,单击页面背景,然后触发更改事件,显示消息.现在当我输入有效值并单击commandButton时,消息会隐藏,但我没有被重定向.当我第二次点击时,我被重定向.
的index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid>
<h:inputText id="value" value="#{bean.value}">
<f:validateRegex pattern="\d+"/>
<f:ajax event="change" execute="@this" render="@this valueMessage"/>
</h:inputText>
<h:message id="valueMessage" for="value"/>
</h:panelGrid>
<h:commandButton value="OK" action="response"/>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
response.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
Value is <h:outputText value="#{bean.value}"/> …Run Code Online (Sandbox Code Playgroud) 我有一个表格的txt文件:
Key:value
Key:value
Key:value
...
Run Code Online (Sandbox Code Playgroud)
我想将所有键及其值放在我创建的hashMap中.如何获取FileReader(file)或Scanner(file)知道何时在冒号(:)分割键和值?:-)
我试过了:
Scanner scanner = new scanner(file).useDelimiter(":");
HashMap<String, String> map = new Hashmap<>();
while(scanner.hasNext()){
map.put(scanner.next(), scanner.next());
}
Run Code Online (Sandbox Code Playgroud) 在部署到本地服务器后,是否可以将JSF应用程序配置为在没有Internet访问的情况下运行?
xmlns="http://www.w3.org/1999/xhtml
xmlns:h="http://xmlns.jcp.org/jsf/html
Run Code Online (Sandbox Code Playgroud)
以上XML命名空间会在部署后出现任何问题吗?
我在WAS 8.0.0.10上使用PF 5.1 + PF Extensions 3.0.0 + OmniFaces 1.8.1
尝试从这里
制作以下示例,<pe:triStateCheckbox/>但是当我更改组件的状态时未调用侦听器,既没有给出错误.
这是我的JSF页面代码:
<pe:triStateCheckbox style="vertical-align:middle;" value="#{bean.notification}">
<p:ajax listener="#{bean.toggleNotification}"/>
</pe:triStateCheckbox>
Run Code Online (Sandbox Code Playgroud)
和豆:
private int notification;
public void toggleNotification() {
System.out.println("toggle");
}
//getters and setters
Run Code Online (Sandbox Code Playgroud)
我可能做错了什么?谢谢.
我不知道如何获得的日期值<p:calendar>在PrimeFaces使用组件的JavaScript
这是我的组成部分
<p:calendar id="calendarInicio"
widgetVar="horaInicioSpin"
value="#{hbean.horaInicial}" timeOnly="true"
pattern="HH:mm" required="true"/>
Run Code Online (Sandbox Code Playgroud)
我需要获取组件的小时值,因为我将<p:calendar>使用JavaScript将该值发送到其他组件.谁能给我一个想法?提前致谢...
我正在使用PrimeFaces的简单fileUpload和自定义提交按钮,如下所示:
<h:form enctype="multipart/form-data">
<p:fileUpload value="#{fileController.file}"
mode="simple"
skinSimple="true"
label="choose file"/>
<p:commandButton value="upload"
ajax="false"
label="upload"
icon="fa fa-upload"
actionListener="#{fileController.upload}"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)
在backing bean中,file是一个类型的属性UploadedFile.
现在我想要upload在没有选择文件的情况下禁用该按钮,但是我无法获得信息,无论用户是否选择了文件,file属性都会保留,null直到upload单击该按钮为止.我试过valueChangeListener的上<p:fileUpload>部件,但是当我点击上传按钮的事件仅触发(但后来为时已晚)
有人有建议吗?
枚举:
public enum OrderStatus {
New("New"),
Paid("Paid"),
Shipped("Shipped"),
Completed("Completed");
private final String label;
private OrderStatus(String label) {
this.label = label;
}
public String getLabel() {
return label;
}
}
Run Code Online (Sandbox Code Playgroud)
enum在<p:dataTable>过滤器中使用类型如下.
<p:dataTable var="row"
value="#{testBacking}"
lazy="true"
rows="10"
widgetVar="dataTableUIWidget">
<p:column id="id" headerText="Id">
<h:outputText value="#{row.orderId}"/>
</p:column>
<p:column headerText="Order Status" filterBy="#{row.orderStatus}">
<f:facet name="filter">
<p:selectOneMenu onchange="PF('dataTableUIWidget').filter();">
<f:selectItem itemLabel="Select" itemValue=""/>
<f:selectItems var="orderStatus"
value="#{enumBean.orderStatus}"
itemLabel="#{orderStatus.label}"/>
</p:selectOneMenu>
</f:facet>
<h:outputText value="#{row.orderStatus}"/>
</p:column>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)
row.orderStatus是enum其关联的JPA实体中的上述类型.
过滤器与<p:selectOneMenu>需要javax.faces.convert.EnumConverter明确指定相关联,因为它的值没有绑定到支持bean属性(否则,根据相关辅助bean中属性的类型,适当的转换器将根据其自身隐式地适当地发挥其作用) .
我希望提到转换器如下
<f:converter converterId="javax.faces.Enum"/>
Run Code Online (Sandbox Code Playgroud)
应该像其他隐式转换器一样工作 …
jsf ×7
primefaces ×5
java ×3
ajax ×1
calendar ×1
comparator ×1
converter ×1
datatable ×1
enums ×1
file ×1
file-upload ×1
javascript ×1
jsf-2 ×1
jsf-2.2 ×1
text ×1