小编Tin*_*iny的帖子

为什么我在Java中出现无法访问的语句错误?

我正在为一个在线教程中找到的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)

java unreachable-statement

2
推荐指数
2
解决办法
288
查看次数

如何仅使用一个Comparator对对象中的所有字段进行排序?

如何使用单个比较器对对象中的所有字段进行排序?

例如:如果我有一个Employee带有三个字段,如对象Name,EidSalary.相反,即写3和比较Namecomparator,EidcomparatorSalarycomparator进行排序,我只需要唯一一个可以进行排序基础上,我提交提供动态比较.

java comparator

2
推荐指数
2
解决办法
664
查看次数

指定p:密码的最小长度

我是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)

jsf primefaces

2
推荐指数
1
解决办法
4453
查看次数

首先单击commandButton不会重定向到另一个页面

  1. 当我输入有效值(仅数字)到inputText并单击commandButton然后我被重定向到response.xhtml.

  2. 当我输入无效值时,单击页面背景,然后触发更改事件,显示消息.现在当我输入有效值并单击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)

ajax jsf jsf-2.2

2
推荐指数
1
解决办法
854
查看次数

Java将txt文件读取到hashmap,用":"拆分

我有一个表格的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)

java text file java.util.scanner

2
推荐指数
3
解决办法
4万
查看次数

JSF应用程序可以配置为在不使用Internet连接的情况下运行吗?

在部署到本地服务器后,是否可以将JSF应用程序配置为在没有Internet访问的情况下运行?

xmlns="http://www.w3.org/1999/xhtml
xmlns:h="http://xmlns.jcp.org/jsf/html
Run Code Online (Sandbox Code Playgroud)

以上XML命名空间会在部署后出现任何问题吗?

jsf xml-namespaces

2
推荐指数
1
解决办法
115
查看次数

pe:triStateCheckbox不适用于p:ajax

我在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)

我可能做错了什么?谢谢.

jsf primefaces jsf-2 primefaces-extensions

2
推荐指数
1
解决办法
588
查看次数

如何从JavaScript中的ap:calendar组件获取Date值?

我不知道如何获得的日期值<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将该值发送到其他组件.谁能给我一个想法?提前致谢...

javascript jsf calendar primefaces

2
推荐指数
1
解决办法
2723
查看次数

检查是否在p:fileUpload中选择了一个文件

我正在使用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>部件,但是当我点击上传按钮的事件仅触发(但后来为时已晚)

有人有建议吗?

jsf file-upload primefaces

2
推荐指数
1
解决办法
3525
查看次数

在p:dataTable过滤器中显式使用隐式JSF转换器javax.faces.convert.EnumConverter

枚举:

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.orderStatusenum其关联的JPA实体中的上述类型.

过滤器与<p:selectOneMenu>需要javax.faces.convert.EnumConverter明确指定相关联,因为它的值没有绑定到支持bean属性(否则,根据相关辅助bean中属性的类型,适当的转换器将根据其自身隐式地适当地发挥其作用) .

我希望提到转换器如下

<f:converter converterId="javax.faces.Enum"/>
Run Code Online (Sandbox Code Playgroud)

应该像其他隐式转换器一样工作 …

datatable jsf enums converter primefaces

2
推荐指数
1
解决办法
4491
查看次数