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

commandButton not able to invoke method  RSS feed

 
naveen gupta
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are the details of my JSF

<h:commandButton id="create" type="submit" action="#{feedBack.create}" alt="#{bundle.buttonPost}" image="#{facesContext.externalContext.requestContextPath}/HTML-INF/images/buttons/post_button.gif"/>


here is my faces-config

<managed-bean>
<description>Feedback Bean</description>
<managed-bean-name>feedBack</managed-bean-name>
<managed-bean-class>com.vrx.web.bean.FeedBackRecordBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

and finally FeeBackRecordBean create method


public String create() {

log(Level.INFO, "FeedBackRecordBean create Begin");

sendEmail();

String response = "feedBack-success";

return response;
}

I don't know why the JSF is not able to invoke the create method
any kind of help would be appreciated
there is a log statement inside the create method
that log itself is not printing

please help
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you sure your command button is inside <h:form> tag ?

Thanks,
 
naveen gupta
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah, it is inside the form, i was wondering

do i need to specify as following in my JSP to call FeedBackRecordBean

<jsp:useBean id="feedBack" class="com.vrx.web.bean.FeedBackRecordBean" scope="request"/>
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm, i never used jsp:usebean in my jsf page.. i faced this issue sometime back, and it got resolved when i kept the button inside form tag. Could you copy your jsp page here ? not the entire page, remove all the components except for the button. did you test it that that way ? maybe something else is messing up ..

thanks,
 
naveen gupta
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
below is my JSF page, i had like 3 text boxes and this button, i just removed the text boxes for this post

i have also post my bean that is FeedBackRecordBean in more detail below this JSF. you can have a look at it. There are logs in my beans class
I was able to see log messages that are in constructor but not the logs that are in create method which is invoked in JSF


JSF

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>


<jsp:useBean id="feedBack" class="com.vrx.web.bean.FeedBackRecordBean" scope="session"/>

<f:loadBundle basename="bundles.commonForm" var="bundle" />

<f:view>
<table width="100%">
<h:form id="feedbackForm">

<td align="right">
<h:commandButton id="create" type="submit" action="#{feedBack.create}" alt="#{bundle.buttonPost}" image="#{facesContext.externalContext.requestContextPath}/HTML-INF/images/buttons/post_button.gif"/>
</td>


</h:form>
</table>
</f:view>



and my FeedBackRecordBean.java


package com.vrx.web.bean;

import java.io.Serializable;
import java.util.logging.Level;
import java.util.ResourceBundle;
import java.util.Date;
import java.util.List;

import com.vrx.commons.bo.feedback.FeedBackBusinessObject;
import com.vrx.commons.persistence.feedback.FeedBackBusinessObjectService;
import com.vrx.commons.logging.LogManager;
import com.vrx.commons.web.jsf.ICRUD;

import com.vrx.commons.email.MailSender;


public class FeedBackRecordBean implements Serializable, ICRUD
{

private FeedBackBusinessObject businessObject;


public FeedBackRecordBean()
{
LogManager.getPlatformLogger().log(Level.INFO, "FeedBackRecordBean Constructor");
this.reset();
}


public FeedBackRecordBean(FeedBackBusinessObject aBusinessObject)
{
this.businessObject = aBusinessObject;
}

public FeedBackBusinessObject getBusinessObject()
{
return businessObject;
}
public void setBusinessObject(FeedBackBusinessObject businessObject)
{
this.businessObject = businessObject;
}


public void reset()
{
LogManager.getPlatformLogger().log(Level.INFO, "reset method ");

this.businessObject = new FeedBackBusinessObject();
//this.businessObject.reset();
this.businessObject.setFeedbackDate(new Date(System.currentTimeMillis()));
this.businessObject.setName(" Naveen Gutta ");
this.businessObject.setDescription(" Enter your feedback here ");

}


public String toString()
{
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("Bean: " + this.getBusinessObject().toString() + "\n");
return stringBuffer.toString();
}



public String create() {

LogManager.getPlatformLogger().log(Level.INFO, "FeedBackRecordBean create Begin");

sendEmail();


LogManager.getPlatformLogger().log(Level.INFO, this.businessObject.toString());

FeedBackBusinessObjectService.getInstance().create(this.getBusinessObject());

LogManager.getPlatformLogger().log(Level.INFO, "FeedBackRecordBean create End");

return null;
}



public void sendEmail()
{

LogManager.getPlatformLogger().log(Level.INFO, "FeedBackRecordBean sendEmail Begin");

ResourceBundle envBundle=ResourceBundle.getBundle("bundles.environment");
String smtpHost = envBundle.getString("mail.smtp.host");
String senderMailAddress = envBundle.getString("mail.smtp.senderMailAddress");
//String senderMailAddress = businessObject.getContactUsRecord().getEmailAddress().getFormattedString();
String customerServiceMailAddress = envBundle.getString("mail.smtp.allEmployeesMailAddress");

MailSender.getInstance(smtpHost).sendMessage(
customerServiceMailAddress,
senderMailAddress,
"Valeant Site Visitor: Feedback",
"\n\nSENDER INFORMATION"
+"\n Name: "+businessObject.getName()
+"\n Date: "+businessObject.getFeedbackDateString()
+"\n Description: "+businessObject.getDescription()
);

LogManager.getPlatformLogger().log(Level.INFO, "FeedBackRecordBean sendEmail End");
}


}
 
naveen gupta
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i see following messages in the log

com.vrx.web.bean.FeedBackRecordBean <init>
INFO: FeedBackRecordBean Constructor

com.vrx.web.bean.FeedBackRecordBean reset
INFO: reset method


To my understanding when it readds the faes-config.xml file, it will initialize the bean and displays the above messages in the log

In the front-end in the text fields i am able to see the default values set in the constructor
 
naveen gupta
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at below JSF code

<td align="right">
<h:commandButton id="create" type="submit" action="#{feedBack.create}" alt="#{bundle.buttonPost}" image="#{facesContext.externalContext.requestContextPath}/HTML-INF/images/buttons/post_button.gif"/>
</td>


what does {facesContext.externalContext.requestContextPath} do ?
 
naveen gupta
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i found solution myself

http://www.coderanch.com/t/211928/JSF/java/JSF-debugging
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!