• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSF Backing Bean

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the Web Application Frameworks forum.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic