Sunday, May 10, 2009

JSF: Refresh Bean AND get different Language bundle per host (Properties)

Hi again,

two small gadgets for you:

1. Get and default bean attributes for different websites or different languages

Sometimes you have the same portlet-code for different websites. I use multiple properties files and select the same within the bean with the following code:

private void initBeanData() {
FacesContext fCtx = FacesContext.getCurrentInstance();

ResourceBundle bundle =
ResourceBundle.getBundle( this.getBundleByHost() , fCtx.getViewRoot().getLocale());
_name = bundle.getString("name_default");
_entryText = bundle.getString("text_default");
}




FacesContext fCtx = FacesContext.getCurrentInstance();
String host = ((PortletRequest)fCtx.getExternalContext().getRequest()).getServerName();
if (host.contains("localhost"))
return "LocalBundle";
...



2. Refresh (backing) Bean

After submitting some input I asked myself how to refresh the backing bean? After some research I found a LOT of people having the same problem.
That seems pretty funny in the meanwhile to me as I realized now how easy that is. Maybe there are some people like me that didn't get it the first time. ;)

Here is the code:

public void reset(ActionEvent actionEvent) {

this.initBeanData();
}


(For the init method: see above :) )

Then of course you have to call the method as always from the view (here: JSP):

9 comments:

  1. I want to refresh only the data table in JSF page when i tried to add a row to the table. Rt now the total page is being refreshed.Please provide me any solution for this.

    ReplyDelete
  2. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    best rpa training in bangalore
    rpa training in bangalore
    rpa course in bangalore
    RPA training in bangalore
    rpa training in chennai
    rpa online training

    ReplyDelete


  3. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

    AWS Training in Bangalore | Best AWS Amazon Web Services…
    Amazon Web Services Training in Pune India
    AWS Online Training in India | AWS Training | AWS online training
    AWS Training in Bangalore | Aws training in Bangalore with placements

    ReplyDelete
  4. This post is so interactive and informative.keep update more information...
    German Classes in Tambaram
    German Classes in chennai

    ReplyDelete

I'm happy about every feedback! :)