Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

f:selectitems issue in jsf  RSS feed

 
Harsha Chaitanya
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have some issue with the JSF.below is code fragment from my jsf page

<f:selectOneChoice id="selectEnvironment" label="#{res['snapshot.label.selectEnvironment']}" value="#{SnapShotManageBean.environment}"
required="true"
requiredMessageDetail="Environment Required"
>
<f:selectItems value="#{EnvironmentManageBean.environmentNames}"/>
</f:selectOneChoice>

below is the backing code for {EnvironmentManageBean.environmentNames} EL

public ArrayList getEnvironmentNames() {
ModelHandler mh = ModelHandler.getInstance();
ArrayList environmentNames = new ArrayList();
try{
will get the list of environmentNames.basically it will talk with BD/Model and It may throw some exceptions

}catch(Exception e){
FacesMessage facesMsg =new FacesMessage(FacesMessage.SEVERITY_ERROR,"",e.getMessage());
FacesContext.getCurrentInstance().addMessage(null, facesMsg);
}
return environmentNames;
}

1. if there is any errors in above mentioned code it will catch it and put in faces messages. the issue is it wont show the messages/exceptions immediately .

i need refresh the page[through command button etc[this works fine for command button e.t.c].can you please help me to solve this issue.

2.Further i read from some other blog that get method mentioned above should not have this exception handling mechanism . so i need to move the code some
where else. can you please suggest some way to do that


Regards,
Harsha
 
Harsha Chaitanya
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
in other words

i have
<f:selectItems value="#{EnvironmentManageBean.environmentNames}"/>

Environment bean has code mentioned below

public ArrayList getEnvironmentNames() {
ModelHandler mh = ModelHandler.getInstance();
ArrayList environmentNames = new ArrayList();
try{
will get the list of environmentNames.basically it will talk with BD/Model and It may throw some exceptions

}catch(Exception e){
FacesMessage facesMsg =new FacesMessage(FacesMessage.SEVERITY_ERROR,"",e.getMessage());
FacesContext.getCurrentInstance().addMessage(null, facesMsg);
}
return environmentNames;
}

when some exception occurs,jsf page wont show it.but when i refresh the page i am able to see the exception can you please help me on this issue
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Where have you put <h:messages> tag? i think it will be at the top of page, means before that radio button thing. So when the page is being rendered, and it reaches to render the radio button and call your bean to get the list, if it gets any error it will not show it because <h:messages> tag is not after your radio button.

To test it place <h:messages> tag after your radio button control.
 
Harsha Chaitanya
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes ,i have included the h:message in JSF code. whenever exception occurs in ModelHandler i am using the FacesMessage to store the exception .
but these messages are not displayed on the screen immediately. but when i refresh the page i am able to see the error message.

say for example

i have selected one combo box which shows no of employees based on company name

say
1. i have selected microsoft
it displays 1xxxx //no database error
2. i have selected ibm
it displays nothing//because of exception . but it doesn't show the exception in UI eventhough i catched the exception and put the exception in FacesMessage [i figure out that exception is thrown using debugger tool].

3. i have selected oracle
it displays 1xxxxxx . UI shows the exception catched before[exception in ibm selected ].

can you please help me on this issue
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the code of your jsp?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!