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

Two commandButtons, one works fine, the other doesn't work  RSS feed

 
ya ji
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two commandButtons in form, one works fine, but the other doesn't work. What's the problem?

code of two buttons:
Doesn't work: <a4j:commandButton action="#{MyBean.createUG}" reRender="ug_panel" limitToList="true" value="Add" styleClass="searchBtn" id="btnAdd"/>

Even I change it to "h:commandButton", still doesn't work!

Works: <h:commandButton action="#{MyBean.addUtoO}" id="btnSubmit" image="/images/btnSubmit.gif"/>
 
Zack Marrapese
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that will happen if the button isn't actually within a form...make sure there is a form tag around that button.
 
ya ji
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Zack,

They are in the form.
The action in the first button isn't invoked, the reRender works.

Ya
 
Anu Sri
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your bean action methods and complete jsp
 
ya ji
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bean Code:
public void createUG(){
try {
AcctMgmt port = getAccountService();
UserGroup ug = new UserGroup();
ug.setName(usergroupname);

Organization o = new Organization();
o.setId(Long.parseLong(selOrg));

ug = port.createUserGroup(o, ug);
} catch (Exception ex) {
ex.printStackTrace();
}
}

xhtml code:
<h:form id="user_form">

<div class="orgLabel">Organization<span class="asterix"> * </span></div>
<div class="orgField">
<h:selectOneMenu id="selOrg" onchange="submit()" valueChangeListener="#{MyBean.changeOrg}">
<f:selectItem itemLabel="Select..." itemValue="0"/>
<f:selectItems value="#{OrganizationBean.allOrgSelectItems}" />
</h:selectOneMenu>
</div>


<div class="formLeft">
Add New Group: <h:inputText value="#{MyBean.usergroupname}" id="ugname"/>
<h:commandButton action="#{My.createUG}" reRender="user_group" limitToList="true" value="Add" styleClass="searchBtn" id="btnAdd" type="submit"/>
</div>

<div class="formLeft">
<h:commandButton action="#{MyBean.addUserToOrg}" id="btnSubmit" image="/images/btnSubmit.gif"/>
</div>
</h:form>
 
Anu Sri
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can you try keeping some debug messages in the action, to trace whether the method is getting invoked or not.

Also the Value attribute is missing for selectOneMenu.

in
<h:commandButton action="#{My.createUG}" reRender="user_group" limitToList="true" value="Add" styleClass="searchBtn" id="btnAdd" type="submit"/>

the bean name is My -- i think this would be a typing error when posting
 
ya ji
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, it's typing wrong, it should be MyBean.

I have some debug information in code, I'm sure that it's not invoked at all.

How to make it be invoked?
 
Laxman Guru
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
are you using JSF 1.1 or JSF 1.2? Change the return type of the action method to String...It will work...
 
ya ji
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.

It works now, but I didn't change the return type

One more question:
Currently, it will refresh the whole page, but I just want to refresh the dataTable in the page.

The button reRender to the outputPanel of the dataTable.

How to make it to only refresh the dataTable?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!