| Author |
<h:selectOneMenu problem. Please, Gurus, I need Your help.
|
Andriy Burachinskiy
Greenhorn
Joined: Dec 31, 2008
Posts: 17
|
|
Hi, guys. Please, could someone help me?
I have following problem: I need to retreive projectNames from DataBase into<h:selectOneMenu ...><f:selectItems ...></f:selectItems></h:selectOneMenu>. I do it this way(part of .jsp page as I think the problem is in it):
----------------------------------------------------------------------------
<h:selectOneMenu value="#{SubmitReport.projectName}"
styleClass="common-dropdown" required="true" >
<f:selectItems value="#{SubmitReport.loggedUserProjects}"/>
</h:selectOneMenu>
----------------------------------------------------------------------------
I succeed in retreiving projectNames from DataBase and displaying on the page. But when I press submit in browser:
----------------------------------------------------------------------------
<h:commandButton value="Submit" id="SubmitCommand" action="#{SubmitReport.submitReport}"
immediate="true">
----------------------------------------------------------------------------
projectName variable of backingBean appears to be null, when it must already have been initialized(there is setter/getter for projectName in backingBean). If I remove immediate="true" in <h:commandButton ...> the page just refreshes, but the submitReport() method of the backingBean is not invoked at all...
In backingBean(SubmitReport) the 2 variables - projectName & loggedUserProjects are:
-----------------------------------------------------------------
private String projectName;
private ArrayList<SelectItem> loggedUserProjects;
public String getProjectName() {
return this.projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public void setLoggedUserProjects(ArrayList<SelectItem> loggedUserProjects) {
this.loggedUserProjects = loggedUserProjects;
}
public ArrayList<SelectItem> getLoggedUserProjects() {
return loggedUserProjects = extractUserProjectsFromDB();
}
-----------------------------------------------------------------
And I tried to change the type of projectName to SelectItem - didn't help.
And one more detail:
I debugged the application, when I press submit in submitReport() of backingBean I tracked the contained values in request like this:
------------------------------------------------------------------
public String submitReport() {
...
Map allParams;
if (this.projectName == null) {
allParams = ((HttpServletRequest)FacesContext.getCurrentInstance().
getExternalContext().getRequest()).getParameterMap();
System.out.println(allParams.size());
}
------------------------------------------------------------------
So in principle if projectName == null, I can retreive it from request "by hands" - but it's wrong, JSF MUST DO THIS. Seems like I configured smt. wrong or misunderstood.
What is the problem in? I have already been fighting this for 2 days - but no luck. So, Gurus, please I need Your help...
|
 |
Smitha H Rao
Ranch Hand
Joined: Oct 20, 2007
Posts: 50
|
|
I know how hard you are trying it from Yeterday.. So I couldn't stop myself giving you few hints to findout the problem.. But this is my last try.. and I suggest you to do following..
Include <h:messages /> in your jsf page. This will give you exact error message happening while setter method is being called.
Also remove immediate="true" on commandbutton. Otherwise you will never come to know about the problem.
Good Luck.
Thanks
Smitha
|
Free Mock tests Interview questions
|
 |
Andriy Burachinskiy
Greenhorn
Joined: Dec 31, 2008
Posts: 17
|
|
Hi, Smitha, thanks for your patience and help. I did as you adviced:
----------------------------------------------------
...
<h:commandButton value="Submit" id="SubmitCommand" action="#{SubmitReport.submitReport}">
<h:messages infoStyle="info"/>
</h:commandButton>
<h:messages infoStyle="info"/>
</h:form>
...
----------------------------------------------------
This is what I can see on the page in browser, when I type "Submit":
_________________________________________________________
Conversion Error setting value 'on track' for 'null Converter'.
Conversion Error setting value 'text of report' for 'null Converter'.
_________________________________________________________
But my submitReport() method of the backingBean is not invoked at all in this case!!! How can I make it get invoked without specifying immediate="true" in submit tag ???
One more thanks for helping me..
|
 |
Smitha H Rao
Ranch Hand
Joined: Oct 20, 2007
Posts: 50
|
|
The problem is in the h:inputTextarea .
you have
<h:inputTextarea id="repContent" value="#{SubmitReport.repContent}" required="true"
styleClass="input" rows="22" cols="75"/>
in you jsf and 'repContent' is a Clob!!
The JSF can do automatic conversion only for wrapper classes.You have to supply a converted for it.
When you submit a JSf page
first all setter methods are called. If there is any problem, action method will not be called. So your action method is not called unless you have immediate="true"
But if you have immediate="true" on commandButton, then no setter method is called.
Right now I think remove this h:inputTextarea from your JSF page and give a try.. It should work properly.
Then write a converter to convert a String to Clob and specify it in the h:inputTextarea tag.
Best Of Luck.
Thanks
Smitha
|
 |
Andriy Burachinskiy
Greenhorn
Joined: Dec 31, 2008
Posts: 17
|
|
|
Thanks, Smitha. You were right. Now my problem is resolved. I'm thankful to you. I was preparing to SCJP1.6 about half year ago, so I've got full study guide by Katty Sierra for SCJP1.6 & exam simulator for SCJP1.6. If You are interested, I can send it to your e-mail. P.s.: the certificate itself is of minor importance, but personally I got to known some interesting things from studyGuide.
|
 |
Smitha H Rao
Ranch Hand
Joined: Oct 20, 2007
Posts: 50
|
|
Thanks Andriy,
Could you please send it to smitha.h.rao@gmail.com.
|
 |
Shasi Mitra
Ranch Hand
Joined: Nov 27, 2008
Posts: 101
|
|
|
can you please send the scjp material to shasimitra@gmail.com also.
|
 |
 |
|
|
subject: <h:selectOneMenu problem. Please, Gurus, I need Your help.
|
|
|