English 中文(简体)
最简单的JSF 2.0应用程序将无法工作
原标题:Simplest JSF 2.0 application will not work

我从未遇到过在JavaEE6中使用最简单的东西时遇到过这样的问题。我有一个非常基础的项目。我试过调试。等等。我不知道该怎么办。

这是我的豆子。

@Named(value = "contactsBean")
@SessionScoped
public class ContactsBean implements Serializable {

   @EJB
   ContactsFacade contactsEJB;
   private List<Contacts> contacts = new ArrayList<Contacts>();  

   public ContactsBean() {

   }

   public String next() {
       contacts = contactsEJB.findAll();        
       return "index";
   }

   /**
     * @return the contacts
   */
   public List<Contacts> getContacts() {
      return contacts;
   }

   /**
    * @param contacts the contacts to set
   */
   public void setContacts(List<Contacts> contacts) {
      this.contacts = contacts;
   }
}

好的,很基本。

这是我的xhtml页面。

 <ui:define name="content">

            <h:form>
                <h:dataTable value="#{contactsBean.contacts}" var="contacts">
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Name"/>
                        </f:facet>    
                        <h:outputText value="#{contacts.name}"/>
                    </h:column>

                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Street"/>
                        </f:facet>    
                        <h:outputText value="#{contacts.street}"/>
                    </h:column>

                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="City"/>
                        </f:facet>    
                        <h:outputText value="#{contacts.city}"/>
                    </h:column>

                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="State"/>
                        </f:facet>    
                        <h:outputText value="#{contacts.state}"/>
                    </h:column>

                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Zip"/>
                        </f:facet>    
                        <h:outputText value="#{contacts.zip}"/>
                    </h:column>

                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Country"/>
                        </f:facet>    
                        <h:outputText value="#{contacts.country}"/>
                    </h:column>

                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Sent?"/>
                        </f:facet>    
                        <h:selectBooleanCheckbox value="#{contacts.sent}" />
                    </h:column>
                </h:dataTable>


                <h:commandButton value="next &gt;" action="#{contactsBean.next}"/>     


            </h:form>

        </ui:define>

好的,当我点击下一个按钮时,我的列表应该会填充。至少它在JavaEE5中总是这样。我不确定我做错了什么。我试着做一个简单的分页器,但即使这样也不行。模型永远不会更新。

到底发生了什么。我在没有EJB的情况下尝试了它,但它也不起作用。

最佳回答

我找到了原因。

有到个不同的包带有SessionScoped注释。

javax.enterprise.context.SessionScoped和javax.faces.context.SessionScope。

由于我使用的是@Named(value=“contactsBean”)注入,所以我需要使用javax.enterprise。@ManagedBean(name=“contactsBeen”)使用javax.faces.context。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签