Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JSF Backing Bean

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am converting from struts to jsf and have a seious issue initializing backing beans for a page.

I want to pre-fill a backing bean and then display its values on a jsf form.

The followig code does not work as it creates a new bean when it encounters the jsf tag:

<%
form.Site site = new form.Site();
site.setSiteName("test");
%>

<f:view>
<h:form>
<h:inputText binding="#{site.siteName}"></h:inputText>
</h:form>
</f:view>


How does one initialze the baking bean ? With struts, I simply created the bean and stuck it in the session.

You help in this matter would be greatly appriciated.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Web Application Frameworks forum.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

just stick it in the faces-config.xml in your WEB-INF folder and iniatilize it with the appropriate values and scope.

<managed-bean>
<description>
The "backing file" bean that backs up the guessNumber webapp
</description>
<managed-bean-name>site</managed-bean-name>
<managed-bean-class>form.Site</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>siteName</property-name>
<property-class>String</property-class>
<value>0</value>
</managed-property>

Then write in your JSF file:

<f:view>
<h:form>
<h:inputText binding="#{site.siteName}"></h:inputText>
</h:form>
</f:view>

That's it!

Florian
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic