Head start JavaServer Faces

霸气de小男生 提交于 2019-12-12 02:24:52

问题


I have a couple of probably common thoughts on JavaServer Faces (JSF) which I want to clear up.

  • Is it possible to just add a Java Class and Call methods inside it from a JSF (x) Page?

I can't see how this even could be an issue knowing to do when you program Java and develop webapplications. However, I can't seem to find a concrete and straight forward guide on this.

As a side-note I am using JDeveloper from Oracle.

I want to be able to just create a JSF Page as easy as I create a ASP.NET Page and from somewhat a "Code-behind" I want to process input and display outcome.

Please guide me in the right direction so I can navigate this JavaServer Faces jungle!


回答1:


it's not generally possible to call arbitrary methods in backing beans from your JSF pages.

I suggest reading a decent JSF book or tutorial (the ones on the IBM website are a little old but still well worth reading).

In general backing beans work using "actions".

So, you define something like this in your page:

<h:commandLink action="#{backingBean.doSomething}" />

Then, in your backing bean you have:

public String doSomething() {
    // Your logic goes here
    return "navigation-target";
}

The String returned from "doSomething" will be a string as defined in your faces-config.xml file, known as an "outcome", which will tell JSF which page to navigate to.

Hope this helps!



来源:https://stackoverflow.com/questions/1464875/head-start-javaserver-faces

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!