小编Wav*_*ter的帖子

验证失败后输入值不会清除

我搜索了很多,但没有找到解决方案.

我正在使用JSF 2.1和RichFaces 4.2.3,并希望验证用户的登录数据

我有两个输入字段.一个用户名和一个密码,两者都有@NotEmpty

login.xhtml

<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:mt="http://java.sun.com/jsf/composite/components">
<h:body>
<ui:composition template="/protected/user/login-template.xhtml">
    <ui:define name="panel-navigation">
        <ui:include src="/protected/user/login-left-menu.xhtml" />
    </ui:define>
    <ui:define name="contentbody">
        <h:form>
            <div id="content">
                <div class="subcolumns">
                    <div class="c65l">
                        <div class="subcl">
                            <p class="sum-error-message" />
                            <fieldset>
                                <h3>
                                    <h:outputText value="#{styleguideMessages.login}" />
                                </h3>
                                <p>
                                    <h:outputText value="#{messages.login_text}" />
                                </p>
                                <div class="subcolumns">
                                    <mt:inputText
                                        id="loginName"
                                        value="#{authenticationPM.loginName}"
                                        label="#{messages.general_label_loginname}"
                                        required="true" />
                                    <div class="c33r validation"></div>
                                </div>
                                <div class="subcolumns">
                                    <mt:inputText
                                        id="password"
                                        value="#{authenticationPM.password}"
                                        label="#{styleguideMessages.db_password}"
                                        required="true"
                                        secret="true" />
                                    <div class="c33r validation"></div>
                                </div>
                                <div class="subcolumns">
                                    <h:commandLink
                                        id="loginButton"
                                        action="#{authenticationPM.doLogin}"
                                        value="#{styleguideMessages.login}" …
Run Code Online (Sandbox Code Playgroud)

validation jsf jsf-2

5
推荐指数
1
解决办法
1312
查看次数

如何为CDI编写Junit测试用例?

我想为cdi编写测试用例.我在我的dao中使用了@inject.任何人都可以帮我如何为cdi编写测试用例.我尝试了下面的代码.但它不起作用.请帮我.

public class StudentTest {

    StudentService stuService;

    StudentDAO stuDAO;

    StudentVO stuVo;

    @Before
    public void setUp() throws Exception {

        System.out.println("In Setup");

        stuVo=new StudentVO ();

        stuService=new StudentService();

        stuDAO=Mockito.mock(StudentDAO.class);

        stuVo.setStudId("123");

        stuVo.setName("user1");

        Mockito.when(stuDAO.getStudent(stuVo.getStuId())).thenReturn(student);
    }

    @Test
    public void getStudent() throws DataAccessException {

        StudentVO stVO=stuService.getStudent(123);

        Assert.assertEquals("123", stVO.getStuId());
    }
}
Run Code Online (Sandbox Code Playgroud)

我的服务类是

public class StudentService {

    @Inject
    StudentDAO stuDao;

    public StudentVo getStudent(String id){

        return stuDao.getStudent(id);

    }

}
Run Code Online (Sandbox Code Playgroud)

在失败时跟踪它只是显示为"java.lang.NullPointerException

 at com.stu.StudentService.getStudent(StudentService.java:104)
 at com.stu.junit.POCJunit.getgetStudent(StudentTest.java:21)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
 at …
Run Code Online (Sandbox Code Playgroud)

java junit junit4 cdi

3
推荐指数
1
解决办法
4290
查看次数

标签 统计

cdi ×1

java ×1

jsf ×1

jsf-2 ×1

junit ×1

junit4 ×1

validation ×1