• 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

Data Population in JSF

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am pretty new to JSF and very confused about its working as well. This may be cause i am still thinking in the struts mode which is causing the problem.

What i have is a simple senario. (using MyFaces)

the User clicks on a link or submits a page. That link has a nivigation

<navigation-rule>
<from-view-id>/helloWorld.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/Profile.jsp</to-view-id>
</navigation-case>
</navigation-rule>

I want to pre populate some values in the bean used in Profile.jsp. How do i do it?
IN struts we had the action class which would allow me to prepopulate. Thats is if i extended LookupDispatchAction then calling the right method would allow me to populate the bean. How do i do this ?
 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using ibmjsf.jar , make use of the post-renderer attribute of <hx:scriptcollector. the post-renderer method will get executed after the page is rendered and you can populate the components with some values when the page gets displayed first.

other option is to go with binding for each components. Try to find some examples on the net, its pretty simple.

Thanks,
 
Sandip Chaudhuri
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please give me some links or something for the examples?
Also i am using MyFaces and my beans are all always in request scope.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order to populate Profile.jsp you set the value of each input field with the method in your backing bean.

I give an example from my project where we want to modify a device values such as name, msisdn, location etc.

<af:inputText id="location" required="true" value="#{ModifyDeviceManager.location}" shortDesc="#{msg['global.device.location.desc']}" />

ModifyDeviceManager is my backing bean and it has an attribute called: location and corresponding getLocation( ) and setLocation( String s) methods. MyFaces uses Java reflection to first get values and on submit set values. If the submit method has no return String ie void modifyDevice() then the same jsp page will be displayed again, with any messages you have added to the context and the getter methods run again showing you that the input fields have been updated with the latest entry.

public String getLocation() {
return this.device.getLocation();
}

public void setLocation(String deviceLocation) {
this.device.setLocation(deviceLocation);
}

So in your case I am guessing you want the getter methods for a user profile to access the database and display the results to the user and if the user updates and submits, then the new values are stored in the database using the setter methods.
 
Sandip Chaudhuri
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh no i am not using the getters and setters that way. That would be impracticle won't it? All i am supposed to do is populate the Value Object and send it to the the interface to deal with.

The retriving and saving of data is done by methods in the backing bean whih pass the Value Object to the Interface(Spring). What i am looking for is how do i fill up the backing bean of the second jsp from the first in such way that the server populates its view.
 
Andrew Och
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to admit that I am a little confused. However if I was to take values in from a user and then display results based on the user's input one way would be to wrap it in a DataModel object (if getters and setters are not practical).

DataModel results = new ListDataModel();
results.setWrappedData(ArrayList of objects you want to display);

<af:outputText value="#{item.realName}" />

If you want values/ objects to be stored in a session to be able to retrieve between different backing beans you could do the following:

public static void storeOnSession(String key, Object object) {
FacesContext ctx = FacesContext.getCurrentInstance();
Map sessionState = ctx.getExternalContext().getSessionMap();
sessionState.put(key, object);
}

public static Object getFromSession(String key) {
FacesContext ctx = FacesContext.getCurrentInstance();
Map sessionState = ctx.getExternalContext().getSessionMap();
return sessionState.get(key);
}

As for database persistance we are using hibernate and I have no knowledge of Spring. I am sorry if my answers are not very helpful.
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic