creating method binding for submit button
I'm tring to create method binding for a submit button , but unfortunately the page isn't submitted when the button is pressed , do you any idea why ?
The code :
protectedvoid setProperties(UIComponent component)
{
....
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();
MethodBinding mb = app.createMethodBinding("#pageBuilder.doSubmit}",new Class[0]);
//create the button
HtmlCommandButton button =new HtmlCommandButton();
button.setValue("browse");
button.setAction(mb);
button.setType("submit");
//add all the components to the panel
List componentKids = component.getChildren();
componentKids.add(button);
}
[1098 byte] By [
jermy111a] at [2007-10-3 2:21:48]

Sorry, I am not sure that this will answer your question but:
1) I guess ("#pageBuilder.doSubmit} should be ("#{pageBuilder.doSubmit}
2) I bind methods with buttons like this:
<h:commandButton value="Create Material" action="#{MaterialControllerBean.createMaterial}" rendered="#{sessionScope.selectedMaterial.materialId == 0}"/>
I am not sure why you are going through all the code you wrote... I find it easier to put the element in the jsf page and render it or not...
> Sorry, I am not sure that this will answer your
> question but:
> 1) I guess ("#pageBuilder.doSubmit} should be
> ("#{pageBuilder.doSubmit}
>
> 2) I bind methods with buttons like this:
> <h:commandButton value="Create Material"
> action="#{MaterialControllerBean.createMaterial}"
> rendered="#{sessionScope.selectedMaterial.materialId
> == 0}"/>
>
> I am not sure why you are going through all the code
> you wrote... I find it easier to put the element in
> the jsf page and render it or not...
this is just a mistype, the original code is correct.
The reason I not doing it from the JSP page is becuase I'm creating a custom component that is composed of several jsf components thus I can't do in a jsp page, it all needs to be done in the java class.
Can you post the HTML source code generated? (right click on the page, view source in the browser)
What do you mean exactly by the page isn't submitted? Is the page refreshed or nothing at all happens in the browser? Do you really have a "pageBuilder" bean (print a message in the constructor) and a "doSubmit" method in it (print a message in it)?
Hi,attempt times: MethodBinding vb = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{pageBuilder.doSubmit}", null);
Hi,
i'm trying to make a binding to a command component as well. And it is kind of working.
Here's my source:
test=new UICommand();
FacesContext t=FacesContext.getCurrentInstance();
Application b=t.getApplication();
MethodBinding test=b.createMethodBinding("#{SessionManager.back}",new Class[0]);
this.test.setAction(test);
Maybe the problem is in the components type?...
Regards,
IL
> it solve it . thank's
Could you please elaborate on how you solved your problem. I am having same issues binding a method to HtmlCommandButton instance using setAction method.
HtmlCommandButton nextButton =
(HtmlCommandButton)application.createComponent(HtmlCommandButton.COMPONENT_TYPE);
nextButton.setValue("Next");
ApplicationFactory factory = (ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
MethodBinding nextAction = factory.getApplication().createMethodBinding("#{myBean.nextFunction}", null);
nextButton.setAction(nextAction);
I myBean:
public String nextFunction()
{
return "next";
}
In facesconfig.xml
<navigation-rule>
<description>Demo</description>
<from-view-id>/page1.jsp</from-view-id>
<navigation-case>
<from-outcome>next</from-outcome>
<to-view-id>/page2.jsp</to-view-id>
</navigation-case>
</navigation-rule>
Use new Class[0] instead of null.
> Use new Class[0] instead of null.Thanks for the reply. I tried that too but it doesn't work.
It's working now... I just had a cup of coffee and added nextButton.setId("nextbutton");and it works.. ;-) .. I wonder why and I also wonder what's the difference between passing a 'null' and 'new Class[0]'? Need to build my theory behind it.
Hello From this action listener can I get the component id which has invoked the action listener.If yes How?
Rojara at 2007-7-14 19:20:45 >

I want To invoke this function as described above public String nextFunction(){return "next";}and some how find which component id has invoked it.How can I do It.Thanks
Rojara at 2007-7-14 19:20:45 >
